ASP.net Ajax Server Control
-
Hi all, I have a composite ASP.NET server control includes a HTML button that shows a div which allows searching capacities, the Search capacities are implimented using AJAX, im inheriting from WebControl and impliementing INamingContainer and ICallbackEventHandler. The Control that works fine if you have just one control on the an ASP.NET page. If you add further controls onto the page the first control still works fully but all contols after that allow the show/hide behaviour but the Ajax bits dont work. There are no errors, the data area just stays blank. I think i have a problem with the way im registering the callback function. this is the code im using which is in the overridded OnPreRender Method of the Server Control.
string sref = Page.ClientScript.GetCallbackEventReference(this, "arg", "display","", true); string Callback = "function GetData(arg, context){" + sref + ";}"; Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "CallBack", Callback, true);
This outputs the following section of html
<script type="text/javascript">
//<![CDATA[
function GetData(arg, context){WebForm_DoCallback('LookupBox23123',arg,display,"",null,true);}//]]>
</script>As you can see the first parameter of the callback contains the ID of the first control added (I know the ID is abit weird). I Think that is why the first control continues to work with Ajax but the rest don't. Is there a way i can pass in the control name to the callback method so i can use multiple controls, or can i amend the script Reference to allow this functionality. Many thanks Phil
-
Hi all, I have a composite ASP.NET server control includes a HTML button that shows a div which allows searching capacities, the Search capacities are implimented using AJAX, im inheriting from WebControl and impliementing INamingContainer and ICallbackEventHandler. The Control that works fine if you have just one control on the an ASP.NET page. If you add further controls onto the page the first control still works fully but all contols after that allow the show/hide behaviour but the Ajax bits dont work. There are no errors, the data area just stays blank. I think i have a problem with the way im registering the callback function. this is the code im using which is in the overridded OnPreRender Method of the Server Control.
string sref = Page.ClientScript.GetCallbackEventReference(this, "arg", "display","", true); string Callback = "function GetData(arg, context){" + sref + ";}"; Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "CallBack", Callback, true);
This outputs the following section of html
<script type="text/javascript">
//<![CDATA[
function GetData(arg, context){WebForm_DoCallback('LookupBox23123',arg,display,"",null,true);}//]]>
</script>As you can see the first parameter of the callback contains the ID of the first control added (I know the ID is abit weird). I Think that is why the first control continues to work with Ajax but the rest don't. Is there a way i can pass in the control name to the callback method so i can use multiple controls, or can i amend the script Reference to allow this functionality. Many thanks Phil
Please ignore this now i've worked it out, although if anyone has a better way let me know. I've used the context to pass the control name through.
string sref = Page.ClientScript.GetCallbackEventReference("context", "arg", "display","context","display_Error", true);
string Callback = "function GetData(arg, context){" + sref + ";}"; Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "CallBack", Callback, true);
this means that in my javascript i've got calls like
GetData(Value,"Lookup1");
Cheers Phil