locked
ASP.NET UpdatePanel refresing the whole page. How to fix this? RRS feed

  • Question

  • User-118859203 posted

    Hi guys,

    I Have 2 DropDownList: DropDownList_1 and DropDownList_2where DropDownList_2 content will be dependent to DropDownList_1 selected value. I'm new in using UpdatePanel.  here is my code:

    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate> <asp:DropDownList ID="DropDownList_1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList_1_SelectedIndexChanged"
    DataSourceID="department" DataTextField="DepartmentNAme" DataValueField="Id"></asp:DropDownList> </ContentTemplate>
    <Triggers> <asp:AsyncPostBackTrigger ControlID="DropDownList_1" EventName="SelectedIndexChanged" /> </Triggers>
    </asp:UpdatePanel> <asp:DropDownList ID="DropDownList_2" runat="server" DataSourceID="subject"
    DataTextField="StudentName" DataValueField="StudentID"></asp:DropDownList>

    CS code:

     protected void DropDownList_1_SelectedIndexChanged(object sender, EventArgs e)
    { SqlDataSource1.SelectCommand = "SELECT DISTINCT * FROM [Student] WHERE StudentID="+DropDownList_1.SelectedValue; DropDownList_2.DataBind(); }

    its working fine as stated above, only the problem is that the whole page refreshes, I also tried removing AutoPostBack="true" in my DropDownList_1 but it stops working, how to fix this? Thanks!

    Tuesday, December 18, 2018 6:13 AM

Answers

  • User-552477072 posted

    Hi Kamalhussain,

    Are you missing Ajax libraries? 

    If so, please import the MicrosoftAjax.js and MicrosoftAjaxWebService in your Scripts folder. It supposed to work. Let me know any more problems. Thanks

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 18, 2018 6:25 AM
  • User-552477072 posted

    Just add EnableEventValidation="false" inside this Ajax page, in <%Page %> directive. Should be fine. Thanks

    Please don't forget to mark as answer if my suggestions help you! Thanks

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 18, 2018 6:43 AM

All replies

  • User-552477072 posted

    Hi Kamalhussain,

    Are you missing Ajax libraries? 

    If so, please import the MicrosoftAjax.js and MicrosoftAjaxWebService in your Scripts folder. It supposed to work. Let me know any more problems. Thanks

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 18, 2018 6:25 AM
  • User-118859203 posted

    Yes it was missing. but after adding Ajax libraries I'm getting another error:

    Sys.WebForms.PageRequestManagerServerErrorException:

    Invalid postback or callback argument. Event validation is enabled using in configuration or <%@ Page EnableEventValidation="true" %> in a page

    Any idea to fix?

    Tuesday, December 18, 2018 6:37 AM
  • User-552477072 posted

    Just add EnableEventValidation="false" inside this Ajax page, in <%Page %> directive. Should be fine. Thanks

    Please don't forget to mark as answer if my suggestions help you! Thanks

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 18, 2018 6:43 AM