Showing posts with label extender. Show all posts
Showing posts with label extender. Show all posts

Saturday, March 24, 2012

Upgrading Extender control from Atlas to ASP.NET AJAX

Hi,

I have an extender control written in atlas. I want to upgrade it to asp.net ajax.

Its so sad that there are no documentation for upgrading an extender control.

My extender control is as follows.

publicclassMyExtender : ExtenderControl<MyTargetProperties>

{

public MyExtender()

{

}

publicstring ControlID

{

get

{

return (string)ViewState["ControlID"] ??"";

}

set

{

ViewState["ControlID"] =value;

}

}

protectedoverridevoid OnInit(EventArgs e)

{

// Init code

base.OnInit(e);

}

protectedoverridevoid OnLoad(EventArgs e)

{

base.OnLoad(e);

}

protectedoverridevoid OnPreRender(EventArgs e)

{

base.OnPreRender(e);

}

protectedoverridevoid RenderScript(Microsoft.Web.Script.ScriptTextWriter writer,Control targetControl)

{

// write the script here

}

}

publicclassMyTargetProperties : TargetControlProperties

{

protectedoverridebool IsEmpty

{

get {returnfalse; }

}

}

Can somebody suggest what I need to do ?

The moment I remove the Microsoft.Web.UI namespace, I get plenty of errors.

Thanks

Hi,

Maybe it's not too hard to start with a new control based on the doc, and migrate your code:

Adding Client Behaviors to Web Server Controls by Using ASP.NET AJAX Extensions

or

Adding Client Capabilities to a Web Server Control by Using ASP.NET AJAX Extensions


hello.

well, several things have change since then but i'll try to recall what yoyu need to do. the first thing is to drop the targetcontrolproperties since they are no longer needed.

the second thing you need to know is that the client behavior object (JS) is introduced in the page through what is know as a ScriptDescriptor object. currently,you have 2 options: ScriptBehaviorDescriptor and ScriptControlDescriptor (it all depends on what you're developing: behaviors or client controls). Besides one of these objects, you'll also need a scriptreference to indicate the client files that must be loaded. what you can't forget is to:

1. during prerender, call registerextendercontrol method

2. during the render method, you must call the registersccriptdescriptors

do notice that if you're extending the extendercontrol class then you don't need to worry about this: just override the abstract getscriptdescriptors and getscriptreferences methods

i still think that the easiest way to understand what's going on is to use reflector and take a look the code you have in the current version of the platform...

Wednesday, March 21, 2012

Urgent | PopupControlExtender

Hi,

I have two UpdatePanels on my web page. and i also have a PopupControl Extender on my page. To simplify UpdatePanel1 has a linkbutton and UpdatePanel2(is inside a panel named "popup") has a label. and PopUpControlExtender is like this.

<cc1:PopupControlExtenderID="PopupControlExtender1"TargetControlID="LnkButton1"PopupControlID="popup"runat="server"></cc1:PopupControlExtender>

I want to show this label as popup when one clicks on LnkButton1. But it gives the following error "An extender can't be in a different UpdatePanel than the control it extends".

How can i achieve the above mentioned?

Thanks

Hi

I had a similar problem with an ModalPopup that was outside of the UpdatePanel that contained my TargetControlID and PopupControlID. What I did is I added the ModalPopup to the update panel.

I guess you could try nesting your UpdatePanel2 into UpdatePanel1.



hi,

Thanks a lot..I moved popUpControlExtender inside panel where my tagetcontrolId also lies, and this worked!!!

thanks a lot

Urgent AutocompleteExtender Does not work

Hello ,

I have aproblem with autocomplete extender in Vb website , it does not work at all never call the webservice

here is the code for the page

<asp:TextBox id="TxtITEM_NO" runat="server" CssClass="dbn_tb" Width="225px" autocomplete="off"></asp:TextBox>
<ajaxToolkit:AutoCompleteExtender ID="AUTOCOMP" runat="server" ServicePath ="MESCService.asmx" ServiceMethod ="GetItemCompletionList"
MinimumPrefixLength="2" CompletionInterval="1000" EnableCaching="true" TargetControlID="TxtITEM_NO" CompletionSetCount="12" />

and this is the code inside MESCService.asmx

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Collections.Generic

<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class MESCService
Inherits System.Web.Services.WebService

<WebMethod()> _
Public Shared Function GetItemCompletionList(ByVal prefixText As String, ByVal count As Integer) As String()
If count = 0 Then count = 20
Dim x As New ikrima.DAL.DBAccess
Dim ds As New System.Data.DataSet
ds = x.ExecuteDataSet("select ITEM_ID FROM ITEM_MASTER ")
Dim items As List(Of String) = New List(Of String)

Dim words As Data.DataRow() = ds.Tables(0).Select("ITEM_ID LIKE '" + prefixText + "%'")
Dim num, i As Integer
num = IIf(words.Length < count, words.Length, count)
For i = 0 To num - 1
items.Add(words(i).Item("ITEM_ID").ToString)
Next
Return items.ToArray
End Function

End Class

can any one help me , why this is not work ,

hi ikrima,

Add the following attribute above your webservice class

[ScriptService]

Regards,


Replace this"<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _"line of yours with -----> <ScriptService()> _


Thanks for our replies

i replace my code and change it to <scriptservice()>_ but till now it does not work , and when try to trace my code i found that the autocompleteExtender does not call the webservice , when ever all other ajaxtoolkit is running well

so what is your suggession to solve this ?


HI Ikrima,

Why do you set the propertyautocomplete="off"> ??

Regards,


HI ,

if you rfer to the samplewebsite which is download with AjaxcontrolToolkit source , you will find in the Autocomplete sample they use it ,

actually i try to remove it also but nothing happend

Thanks


Move your MESCService.asmx to your ScriptManager

e.g.

<asp:ScriptManager runat="server" ID="ScriptManager1" EnablePartialRendering="true">
<services>
<asp:servicereference path="~/MESCService.asmx" />
</services>
</asp:ScriptManager>

Hope it works. For it works. For me it does.


Sad , still not working................

Even there is no query on server or any response/request from the page it just ignore it


Sad , still not working................

Even there is no query on server or any response/request from the page it just ignore it


hi i have the same problem in c#,so if u find any solution,please post it here

thanx


replace "<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _" with "<System.Web.Script.Services.ScriptService()> _"


Have you found a solution to your problem?

I found the solution, it seems that the Function name DOES matter. Here is my webservice code returning a generic string array:

Imports

System

Imports

System.Web

Imports

System.Collections

Imports

System.Web.Services

Imports

System.Web.Script.Services

Imports

System.Web.Services.Protocols

Imports

System.Data.SqlClient

<System.Web.Script.Services.ScriptService()> _

<WebService(Namespace:=

"http://tempuri.org/")> _

<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _

<

Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _

Public

Class WebServiceInherits System.Web.Services.WebService

<WebMethod()> _

<ScriptMethod()> _

PublicFunction GetCompletionList(ByVal prefixTextAsString,ByVal countAsInteger)AsString()Dim strArray(2)AsString

strArray(0) =

"abc"

strArray(1) =

"def"

strArray(2) =

"ghi"Return strArrayEndFunction

End

Class

urgent: Modal popup Extender is not closing after validation fires

I have an edit modalpopupextender inside the gridview that appear when linkbutton is clicked all of this inside an update panel and its working great.

when the modalpopupextender popsup i have two buttons "Close" and "Save" button and when the user click on "Close" it closes the modalpopupextender - again its working great.

but the problem isthat, when i click on "Save" button it FIRES validation and in the modalpoupextender i have twocustomvalidation controlsthat validates whether the user have check at least one checkbox or not so when the user hit on "Save" button the validation fires whic is great so far butwhen i clik on "Close" button its not closing my modalpopuextender ?

here is my close button looks like:

<ajaxToolkit:ModalPopupExtender ID="mpePerson" runat="server" TargetControlID="btnHiddenPerson"
PopupControlID="pnlPerson" OkControlID="bModalDialogCancel"CancelControlID="bModalDialogCancel" BackgroundCssClass="modalBackground"
PopupDragHandleControlID="PersonCaption">
</ajaxToolkit:ModalPopupExtender>

<asp:ButtonCausesValidation="false"ID="bModalDialogCancel" runat="server"Text=" Close "ToolTip="Close this window"/>

what is going on here?

You have your OkControlID and your CancelControlID both pointing to the same button ('bModalDialogCancel').

------------------
When you ask a question, remember to click "mark as answered" when you get a reply which answers your question.


i fixed myself, i was passing the wrong id.

thanks.

Use Custom Objects as Extender Control Properties - Part II

I thought this post -http://pietschsoft.com/Blog/Post.aspx?PostID=1377 - was very useful in further developing a custom ajax control extender. Thanks to Chris Pietschmann for posting his work.

I expanded his work to override the ConvertFrom method to JSON deserialize a string back to the custom object. In this example, I am using a Person object. Please refer to Chris's article for code and adapt the code with the changes I made below in bold italics:

GenericTypeConverter class:

namespace SandboxClass{public class GenericTypeConverter<T> : TypeConverter {public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture,object value, Type destinationType) { JavaScriptSerializer jss =new JavaScriptSerializer();string s = jss.Serialize(value);return s; }public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture,object value) {if (value is string) { JavaScriptSerializer jss =new JavaScriptSerializer(); T t = jss.Deserialize((string)value);return t; }else return base.ConvertFrom(context, culture,value); } }}
Person class:
namespace SandboxClass{ [TypeConverter(typeof(GenericTypeConverter<Person>))]public class Person {private string _FirstName;public string FirstName {get {return _FirstName; }set { _FirstName =value; } }private string _LastName;public string LastName {get {return _LastName; }set { _LastName =value; } } }}
 
Default.aspx
 
public partialclass _Default : System.Web.UI.Page{protected void Page_Load(object sender, EventArgs e) {if (!Page.IsPostBack) { // serialize object to string to pass to client SandboxClass.Person person =new SandboxClass.Person(); person.FirstName ="John"; person.LastName ="Doe"; ajaxControlExtender.MyPerson = person; }else { // deserialize object back from client to your custom object, in this example, the Person object SandboxClass.GenericTypeConverter gc = System.ComponentModel.TypeDescriptor.GetConverter(typeof(SandboxClass.Person))as SandboxClass.GenericTypeConverter; SandboxClass.Person person = (SandboxClass.Person)gc.ConvertFromString(ajaxControlExtender.ClientState); Label2.Text = person.FirstName +" " + person.LastName; } }}
 
Also, in addition to step 5 of Chris's post and after manipulating the object on client-side, I am assigning the object to the ajax control extender ClientState property
to maintain state back to the server so the deserialization process can perform. Below is an example to include in the ajax control extender js file:
 
this._MyPerson.FirstName ='Jane';this._MyPerson.LastName ='Smith';this._MyPerson = Sys.Serialization.JavaScriptSerializer.serialize(this._MyPerson);this.set_ClientState(this._MyPerson);
Enjoy!

Thanks for your sharing.


Continuing to expand on this... It looks like this requires more work when one wants to serialize and deserialize an object with nested objects. Ugh... Any input or ideas to quickly move this along would be appreciated. I am thinking this will involve some recursive logic.


As an additional reference -http://www.manuelabadia.com/blog/PermaLink,guid,22a125d3-1ed3-422b-ba2b-89ed63febce3.aspx

It looks like I need to implement a JavaScriptResolver...


Well well... Sure enough, the JavaScriptResolver solves the problem with nested objects. The link in my previous post above explains it all.

Modified the code below in bold italics -

namespace SandboxClass{public class GenericTypeConverter : TypeConverter {public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture,object value, Type destinationType) { JavaScriptSerializer jss =new JavaScriptSerializer(new SimpleTypeResolver());string s = jss.Serialize(value);return s; }public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture,object value) {if (value is string) { JavaScriptSerializer jss =new JavaScriptSerializer(new SimpleTypeResolver()); T t = jss.Deserialize((string)value);return t; }else return base.ConvertFrom(context, culture,value); } }}

I am looking to move this JSON serialization of a custom object out of an AJAX control extender into a custom AJAX client control.

I have this part in my custom AJAX client control -

 IEnumerable IScriptControl.GetScriptDescriptors() { ScriptControlDescriptor descriptor =new ScriptControlDescriptor("CGAjaxClientControls.CGRadioButtonList",this.ClientID); descriptor.AddProperty("result",this.Result); descriptor.AddProperty("targetAction",this.TargetAction);return new ScriptDescriptor[] { descriptor }; }
The 'result' is just a string. That's the easy part but 'targetAction' is a custom object with nested objects as well.
The problem is I get this error message trying to deserialize on the client.

Sys.ArgumentTypeException: Object of type 'Object' cannot be converted to type 'String'. Parameter name: data

Here is the $create -

Sys.Application.add_init(function() { $create(CGAjaxClientControls.CGRadioButtonList, {"result":"Test","targetAction":{"ID":0,"TargetRadioButtonListId":"CGRadioButtonList1","RadioButton":[{"ID":0,"Text":"Yes","Value":"True","Selected":false,"Container":"panel","TargetControlId":"divCGRadioButtonList1Y"},{"ID":1,"Text":"No","Value":"False","Selected":false,"Container":"panel","TargetControlId":"divCGRadioButtonList1N"}]}},null,null, $get("CGRadioButtonList1"));});

Can anyone help me crack this? I do notice the type resolver tags are not getting added.

Thanks!


I think I've got this figured out. It is not required to deserialize the object when you create a custom AJAX client control. It's already done for you through IScriptControl.