Why does asp:UpdatePanel would not work in such situation?

Last post 05-12-2008 11:23 PM by chetan.sarode. 1 replies.

Sort Posts:

  • Why does asp:UpdatePanel would not work in such situation?

    05-12-2008, 2:58 AM
    • Loading...
    • utkuozan
    • Joined on 12-14-2006, 1:51 PM
    • Izmir/TURKEY
    • Posts 76

    Hi all, I am using asp:UpdatePanel and asp:ScriptManager pair to prevent my page postback between in-page changes. I have several pages and these two work perfect on all pages but one page. On this page at the top there are several buttons and at the top there is a form. But when I click one of the buttons to send the page a parameter in the URL bar the page postbacks. No other pages do that. The only code related to the buttons is the following one. Why do you think that might fail to convert postback to callback please?

    Regards:

    My code:

    1        protected void ButtonClick(object sender, EventArgs e)
    2        {
    3            Button btnA = (Button)sender;
    4            string btnName = btnA.ID;
    5            btnName = btnName.Replace("btn", "");
    6            string currentPath = Request.Url.AbsoluteUri;
    7            string[] pathsVars = currentPath.Split('?');
    8            currentPath = pathsVars[0].ToString();
    9            Response.Redirect(currentPath + "?title=" + btnName);
    10       }

     
    Utku Ozan ÇANKAYA
  • Re: Why does asp:UpdatePanel would not work in such situation?

    05-12-2008, 11:23 PM
    Answer

    It is not a good practice to use Response.Write or server.execute from within an ASP.NET page in general. As UpdatePanels work by intercepting the page rendering process you are recieving the errors.

    You can put the code to generate the data in an HTTPHandler or you can make the button a PostBackTrigger.

    Because of the way updatepanels manage the DOM elements within them, you cannot use Response.Write() with them.

    Chetan Sarode
    Software Engineer,
    Approva Systems Pvt Ltd,
    Pune, India.
Page 1 of 1 (2 items)