Page view counter

Ajax and Response.Write

Last post 11-04-2008 11:58 PM by Mr. Javaman. 16 replies.

Sort Posts:

  • Ajax and Response.Write

    03-06-2007, 8:12 AM
    • Loading...
    • js2004
    • Joined on 03-02-2007, 3:11 PM
    • Posts 17
    • Points 19

    It seems like you cannot use Ajax on a page which has response.write on it. Did anyone find a solution to this problem?

     Thanks,

     jsmith

    Filed under:
  • Re: Ajax and Response.Write

    03-06-2007, 9:22 AM
    • Loading...
    • paul.vencill
    • Joined on 02-01-2006, 12:57 PM
    • Gaithersburg, MD
    • Posts 1,062
    • Points 4,802

    It's not a problem; I've done it.  Can you post code?

    Help those who have helped you... remember to "Mark as Answered"
  • Re: Ajax and Response.Write

    03-06-2007, 11:48 AM
    • Loading...
    • fcedotal
    • Joined on 08-28-2002, 4:57 PM
    • Posts 11
    • Points 56

     I am having the same problem displaying a modla dialog.  It used to work, but when the panel that contains the button that ran the code  to display the modal dialog is wrapped in an update panel, it quit working.

     

      Private Sub btnShowSpargerParms_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnShowSpargerParms.Click
            MakeModelInputTable()
            Response.Write("<script language='javascript'>showModalDialog('SpargerChooser.aspx', null,'status:no;dialogWidth:400px;dialogHeight:650px;dialogHide:false;help:no;scroll:no');</script>")
        End Sub

     MakeModelInputTable gets some parameters from the current page, puts them into a session variable, then I display the modal dialog which does some calculations in the pageload using the parameters in the session variable, then displays the results on the modal dialog.

     

     

     

  • Re: Ajax and Response.Write

    03-06-2007, 12:03 PM
    • Loading...
    • Lovely
    • Joined on 10-24-2006, 7:34 PM
    • Posts 104
    • Points 379

    You can use the RegisterStartupScript method in this POST,

    and showModalDialog in the same way.

     

    Regards.

  • Re: Ajax and Response.Write

    03-06-2007, 1:47 PM
    Answer
    • Loading...
    • fcedotal
    • Joined on 08-28-2002, 4:57 PM
    • Posts 11
    • Points 56

    Thanks, it is working now.  This is what the new code looks like:

     

            MakeModelInputTable()
            ScriptManager.RegisterStartupScript(updAgitData, updAgitData.GetType, "key", "<script language='javascript'>showModalDialog('SpargerChooser.aspx', null,'status:no;dialogWidth:400px;dialogHeight:650px;dialogHide:false;help:no;scroll:no');</script>", False)

  • Re: Ajax and Response.Write

    03-06-2007, 9:25 PM
    • Loading...
    • js2004
    • Joined on 03-02-2007, 3:11 PM
    • Posts 17
    • Points 19

    Here is a discussion of the error:

    http://dotnetdebug.net/2006/12/28/syswebformspagerequestmanagerparsererrorexception/

     But I cannot use the solution discussed here.

    jsmith

     

    Filed under:
  • Re: Ajax and Response.Write

    03-07-2007, 8:03 AM
    • Loading...
    • Lovely
    • Joined on 10-24-2006, 7:34 PM
    • Posts 104
    • Points 379
    js2004:

    Here is a discussion of the error:

    http://dotnetdebug.net/2006/12/28/syswebformspagerequestmanagerparsererrorexception/

     But I cannot use the solution discussed here.

    jsmith

     

    Response.Write not support with ASP.NET AJAX . You can use Scriptmanager mothod like the post before. Or put your text in a Lable,"This suggestion from the blog you put it up". Regards.
  • Re: Ajax and Response.Write

    03-07-2007, 8:04 AM
    • Loading...
    • Lovely
    • Joined on 10-24-2006, 7:34 PM
    • Posts 104
    • Points 379
    js2004:

    Here is a discussion of the error:

    http://dotnetdebug.net/2006/12/28/syswebformspagerequestmanagerparsererrorexception/

     But I cannot use the solution discussed here.

    jsmith

     

    Response.Write not support with ASP.NET AJAX . You can use Scriptmanager mothod like the post before. Or put your text in a Lable,"This suggestion from the blog you put it up". Regards.
  • Re: Ajax and Response.Write

    03-07-2007, 4:45 PM
    • Loading...
    • js2004
    • Joined on 03-02-2007, 3:11 PM
    • Posts 17
    • Points 19

    That is right I can use ScriptManger.RegisterStartupScript(or RegisterClientScriptBlock). But that script gets written in page when it is loaded.

    But that does not meet requirements if I have to dynamically write javascript during an ajax method call.

    Consider the case: Trying to use Ajax to handle the OnMenuItemClick event of Asp:Menu, I need to warn users through a dialog box that if they navigate away from the page their data will be lost. Easy solution will be to do a Response.Write(confirm) in the event. But because of the inability of Ajax and Response.Write to work together I had to do a lot of twists to get the same effect. Even if I write javascript to a literal control and add it to page at run time I get the same error. I am not sure if I write javascript to a label it will work.

     That is why I was wondering if there is a way to use Ajax and Response.Write at the same time in a page.

    Best Regards,

    jsmith

  • Re: Ajax and Response.Write

    03-07-2007, 4:50 PM
    • Loading...
    • js2004
    • Joined on 03-02-2007, 3:11 PM
    • Posts 17
    • Points 19
    paul.vencill:

    It's not a problem; I've done it.  Can you post code?

    Have you used Ajax.net v1.0 and Response.Write together?

    Regards,

    jsmith

    Filed under: ,
  • Re: Ajax and Response.Write

    03-07-2007, 5:31 PM
    Answer
    • Loading...
    • Lovely
    • Joined on 10-24-2006, 7:34 PM
    • Posts 104
    • Points 379

    You can use this way:

     protected void Menu1_MenuItemClick1(object sender, MenuEventArgs e)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "key", "confirm('Are you sure you want to delete?');", true);
        }
     
  • Re: Ajax and Response.Write

    03-07-2007, 6:12 PM
    Answer
    • Loading...
    • fcedotal
    • Joined on 08-28-2002, 4:57 PM
    • Posts 11
    • Points 56

    I think what is happening is this: (but won't bet my life on it!)

    When you put something in your code-behind page that renders javascript, Ajax is controlling javascript at this point and it won't let anything else get rendered, UNLESS you register the script in your code behind page.

    Registering the script lets Ajax know that javascript is being rendered, so Ajax know what to do with it.

    I wish one of the Microsquish weenies would respond to this. 

    fcedotal

  • Re: Ajax and Response.Write

    03-07-2007, 7:46 PM
    Answer
    • Loading...
    • Steve Marx
    • Joined on 05-26-2006, 8:35 PM
    • Microsoft
    • Posts 643
    • Points 2,460

    The response from the server from an async postback has to have a particular format so that the AJAX Library running in the browser can parse it.  Response.Write changes the format of the response, making it unparsable.  That's why Response.Write is incompatible with asynchronous postbacks.

    For examples such as the one in this thread, ScriptManager.RegisterStartupScript(...) is usually what you need.

    Yours Truly,
    Steve Marx
    Microsquish Weenie

    Steve Marx | ASP.NET AJAX Evangelist | Microsoft Corporation
  • Re: Ajax and Response.Write

    03-09-2007, 8:28 AM
    • Loading...
    • js2004
    • Joined on 03-02-2007, 3:11 PM
    • Posts 17
    • Points 19
    Steve Marx:

    The response from the server from an async postback has to have a particular format so that the AJAX Library running in the browser can parse it.  Response.Write changes the format of the response, making it unparsable.  That's why Response.Write is incompatible with asynchronous postbacks.

    For examples such as the one in this thread, ScriptManager.RegisterStartupScript(...) is usually what you need.

    Yours Truly,
    Steve Marx
    Microsquish Weenie

     

    Ok. Thank you Steve.

     jsmith

  • Re: Ajax and Response.Write

    03-31-2008, 9:40 AM
    • Loading...
    • gkopparam
    • Joined on 01-31-2008, 9:27 PM
    • Posts 21
    • Points 9

    How will i be able use registerStratup script when i want to write back a new form to the client and then, do a submit of that for i just created.

     

    <form name=ABC id=ABC action="/test.aspx"  method=post ><input type=hidden name="txtBox" value="test"></FORM>

    <script language="javascript"> document.ABC.submit()</script>

     

    but when i use response.write in normal pages the above works absolutely fine. but in AJAX enabled web pages it gives me the 500 error .

    thanks

Page 1 of 2 (17 items) 1 2 Next >