Monday, March 26, 2012

developing composite control that combines Ajax controls

Hi,

Is it possible to write a composite control that consists of UpdatePanels, and other control from Ajax Control Toolkit?

I would be happy to view some examples on developing this kind of control.

Thanks

Hello,

You can do this. It is possible.

I suggest that you use a scriptmanagerproxy in your control in case the page containing the control has a scriptmanager already. Aslo, you may have an easier time using the update panel in the containing page instead of in the control to get the ajax capabilities.

Good Luck,

Louis


Hi,

Thanks for the reply, do you suggest to put the composit control inside an update panel?

Im planning to build two build two composite controls:

one of them should contain an AutoCompleteExtender and other simple web controls . so I guess there wont be any problem with it.

but the other control will contain a TabContainer (from the Ajax Control Toolkit) I thought to put on each tab panel's content template an update panel (to reduce the amont of rerendered data, and save bandwith)

do you think that in this case its better to locate the whole TabContainer inside one UpdatePanel?

Thanks,

Tal


Yes, I suggest not including the update panel in the usercontrol.


Hi,

Im writting a composite control as I described in my first post (combines AutoCompleteExtender and FilteredTextBoxExtender and a TextBox)

I wrote the following Render function :

1 SearchAutoComplete =new AutoCompleteExtender();2 SearchAutoComplete.ID ="SearchAutoComplete";3 SearchAutoComplete.MinimumPrefixLength = 3;4 SearchAutoComplete.BehaviorID ="AutoCompleteBehavior";5 SearchAutoComplete.EnableCaching =true;6 SearchAutoComplete.CompletionSetCount = 5;7 SearchAutoComplete.UseContextKey =true;8 SearchAutoComplete.ServiceMethod ="GetCompletionList";9 SearchAutoComplete.TargetControlID ="SearchTextBox";10//SearchAutoComplete.OnClientItemSelected = "";1112 SearchFilteredTextBox =new FilteredTextBoxExtender();13 SearchFilteredTextBox.ID ="SearchFilteredTextBox";14 SearchFilteredTextBox.TargetControlID ="SearchTextBox";15 SearchFilteredTextBox.BehaviorID ="FilteredTextBoxBehavior";16 SearchFilteredTextBox.FilterType = AjaxControlToolkit.FilterTypes.Custom | FilterTypes.Numbers;1718 SearchByNameLabel =new Label();19 SearchByNameLabel.ID ="SearchByNameLabel";20 SearchByNameLabel.Text = Resources.Resource.SearchByName;2122 SearchByNumberLabel =new Label();23 SearchByNumberLabel.ID ="SearchByNumberLabel";24 SearchByNumberLabel.Text = Resources.Resource.SearchByNumber;2526 SearchTextBox =new TextBox();27 SearchTextBox.ID ="SearchTextBox";2829this.Controls.Add(SearchAutoComplete);30this.Controls.Add(SearchFilteredTextBox);31this.Controls.Add(SearchByNameLabel);32this.Controls.Add(SearchByNumberLabel);33this.Controls.Add(SearchTextBox);
1 AddAttributesToRender(writer);23 writer.AddAttribute(4 HtmlTextWriterAttribute.Cellpadding,5"1",false);6 writer.RenderBeginTag(HtmlTextWriterTag.Table);7 writer.RenderBeginTag(HtmlTextWriterTag.Tr);8 writer.RenderBeginTag(HtmlTextWriterTag.Td);9 SearchByNameLabel.RenderControl(writer);10 writer.RenderEndTag();11 writer.RenderBeginTag(HtmlTextWriterTag.Td);12 SearchByNumberLabel.RenderControl(writer);13 writer.RenderEndTag();14 writer.RenderBeginTag(HtmlTextWriterTag.Td);15 SearchAutoComplete.RenderControl(writer);16 writer.RenderEndTag();17 writer.RenderBeginTag(HtmlTextWriterTag.Td);18 SearchFilteredTextBox.RenderControl(writer);19 writer.RenderEndTag();20 writer.RenderEndTag();21 writer.RenderEndTag();22

and got the following Exception:

"Error: Sys.ArgumentException: value must not be null for controls and behaviors.

parameter name:element"

Any idea?

Thanks


hi,

change

SearchAutoComplete.TargetControlID ="SearchTextBox"

to be

SearchAutoComplete.TargetControlID = SearchTextBox.ClientID

the script is hassling you about being unable to find the targetControl


Hi,

Thanks for your reply.

I want my WebMethod to be integrated with the CompositeControl (Im not intersted in Exposing it as a top level property).

How can I embed a web-service with the control (I prefer using PageMethod fo GetCompletionList). ?

I read somewhere that I should write a custom HttpHandler ( if i want my CompositeControl to use my embedded webservice) , It seems complicated , do you have en example for this?

or better , a solution for how I can use an "embedded" PageMethod?

Thanks,

Tal


Hi Tal,

It's not recommended to embed the pageMethod inside a UserControl.

By default, a client can't request for a user control( with extension .ascx) directly, it's blocked by the a special handler that prevents accessing. It's not recommend to change this behavior.

May be you are trying to implement a user control that is easy to maintain and use, but if the user has to pay more to get accustom to this.


Hi,

Im Writting a CompositeControl not a UserControl.

so actually Im trying to "embed" the PageMethod or Web-service method (GetCompletionList method) inside the DLL of my CompositeControl.

Is there a way to solve this?

(im not interesting in exposing the AutoCompleteExtender's ServiceMethod property)

I want that the logic of geting the completion results will be a part of my CompositeControl.

Thanks


It's also not allowed to access a assembly on client side directly.

There should always an endpoint( a class implement IHttpHandler interface ) on the server be responsible for processing a request. You may implement a class and use it to invoke the method in the dll.


Hi,

Do you have any refferences for how to implement such a class?

I have know idea how to write an HttpHandler that invokes a web-service that is embedded in a DLL...

Thanks


Hi,

Just create a class that implementIHttpHandlerinterface. And you may refer to the ScriptResourceHandler class in thesource code of ajax extension for a practical implementation of it.


Hi,

Thanks for the reply. I will have a look at the source code of ajax extension.

Do you think I should also implement an HttpHandlerFactory?

As I understand my custom HttpHandlerFactory will check all *.asmx requests,

if the asmx request is for my AutoComplete web service return my custom HttpHandler, otherwise return the default one.

is this correct?


Not necessary, you may register the Handler to a specific file name in web.config.

But if you plan to use .asmx, why don't you add a web service directly. It's a implicit httpHandler.


Hi,

what do you mean by "adding the web-service directly"?

No comments:

Post a Comment