Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. ASP.net Ajax Server Control

ASP.net Ajax Server Control

Scheduled Pinned Locked Moved ASP.NET
csharpjavascripthtmlasp-netsysadmin
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PJWindsor
    wrote on last edited by
    #1

    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

    P 1 Reply Last reply
    0
    • P PJWindsor

      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

      P Offline
      P Offline
      PJWindsor
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups