Having trouble injecting Javascript in AJAX enabled page withRegisterClientScriptBlock

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • CrystalMikeMD@gmail.com

    Having trouble injecting Javascript in AJAX enabled page withRegisterClientScriptBlock

    Greetings,

    I've been at this problem for some time now and have decided to seek
    out some help.

    Essentially, this is what I have. A basic ASP.NET 2.0 page. On this
    page is the standard <formtag. Under that, we have an UpdatePanel
    object where the rest of my partial rendering controls live. There is
    simply a basic control, such as a Literal or Label in the
    UpdatePanel. When a button is clicked on the page, I want to send out
    Javascript back to the Label or Literal (set the Text property of this
    control with javascript) such as "<script>alert( 'hello');</script>"

    The problem? Whatever I send to the control gets there but nothing is
    ever executed.

    So, I have started trying RegisterClientS criptBlock() on the top level
    "Page" object and even at the inner control level.

    Nothing seems to happen.

    If I inject javascript in the "Page_Load" method, it runs and works.
    However, I need to inject javascript at a later time after the page
    loads (since this is AJAX).

    Does anyone have any words of advice? Anyone that has been down this
    road? I sure would appreciate some help.
  • CrystalMikeMD@gmail.com

    #2
    Re: Having trouble injecting Javascript in AJAX enabled page withRegisterCli entScriptBlock

    I got it.

    Use the STATIC method "RegisterClient ScriptBlock" instead of the
    ClientScriptMan ager for a control.

    Something like this will work globally:

    Microsoft.Web.U I.ScriptManager .RegisterClient ScriptBlock(Upd atePanel1,
    typeof(UpdatePa nel),“TestKey”, “alert(’Test’); “, true);

    Two days wasted but now I feel better.

    Comment

    • bruce barker

      #3
      Re: Having trouble injecting Javascript in AJAX enabled page withRegisterCli entScriptBlock

      you server injected client to be render from a update panel postback,
      you code needs to call the ScripManager.Re gisterClientScr iptBlock and
      this call must be from a control inside the update panel. this is
      because only html/script rendered inside the update panel is returned to
      the client.


      -- bruce (sqlwork.com)


      CrystalMikeMD@g mail.com wrote:
      Greetings,
      >
      I've been at this problem for some time now and have decided to seek
      out some help.
      >
      Essentially, this is what I have. A basic ASP.NET 2.0 page. On this
      page is the standard <formtag. Under that, we have an UpdatePanel
      object where the rest of my partial rendering controls live. There is
      simply a basic control, such as a Literal or Label in the
      UpdatePanel. When a button is clicked on the page, I want to send out
      Javascript back to the Label or Literal (set the Text property of this
      control with javascript) such as "<script>alert( 'hello');</script>"
      >
      The problem? Whatever I send to the control gets there but nothing is
      ever executed.
      >
      So, I have started trying RegisterClientS criptBlock() on the top level
      "Page" object and even at the inner control level.
      >
      Nothing seems to happen.
      >
      If I inject javascript in the "Page_Load" method, it runs and works.
      However, I need to inject javascript at a later time after the page
      loads (since this is AJAX).
      >
      Does anyone have any words of advice? Anyone that has been down this
      road? I sure would appreciate some help.

      Comment

      Working...