locked
avoid postback in dropdownlist RRS feed

  • Question

  • User-439809512 posted

    Hi

    Am using dropdownlist control in my project. it is set autopostback true for getting data from database . while display the data the asp.page is refreshing on every time. so how to avoid refresh the page  while select dropdownlist control .

    some of my friends suggesting to use updatepanel and some suggest not use ajax control .

    Pls suggest the best

    Tuesday, January 7, 2014 6:18 AM

Answers

  • User-760709272 posted

    If you don't want autopostback, don't use an asp:DropDown.  If you want to use asp:DropDown with no page refresh then use an UpdatePanel.  You can't mix and match, it is one or the other.  If your alert isn't working, re-arrange your code so that it does work.  If you put the code that renders the javascript to make the alert happen inside the updatepanel it should work.  But there are lots of reasons as to why your alert might not be working but we'd need to see the code to work out why.  Just wrapping the dropdown in an updatepanel isn't going to solve your problem, you have to work out exactly what the updatepanel has to go around.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 7, 2014 6:42 AM
  • User-1509636757 posted

    alert message could not be display

    Well, we can. Sample Code:

            <asp:ScriptManager runat="server" />
            <asp:UpdatePanel runat="server">
                <ContentTemplate>
                    <asp:DropDownList runat="server" ID="ddlTest" AutoPostBack="true" OnSelectedIndexChanged="ddlTest_SelectedIndexChanged">
                        <asp:ListItem Text="text1" />
                        <asp:ListItem Text="text2" />
                    </asp:DropDownList>
                </ContentTemplate>
            </asp:UpdatePanel>
        protected void ddlTest_SelectedIndexChanged(object sender, EventArgs e)
        {
            ScriptManager.RegisterClientScriptBlock(this, typeof(string), "TestScript", "alert('Sample Alert');", true);
        }



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 7, 2014 7:22 AM

All replies

  • User-760709272 posted

    Using an UpdatePanel will probably be the easiest solution

    Tuesday, January 7, 2014 6:28 AM
  • User-1509636757 posted

    Place the dropdownlist control inside UpdatePanel will be easy to avoid full postback:

            <asp:ScriptManager runat="server" />
            <asp:UpdatePanel runat="server">
                <ContentTemplate>
                    <asp:DropDownList runat="server" ID="ddlTest" AutoPostBack="true" OnSelectedIndexChanged="ddlTest_SelectedIndexChanged">
                        <asp:ListItem Text="text1" />
                        <asp:ListItem Text="text2" />
                    </asp:DropDownList>
                </ContentTemplate>
            </asp:UpdatePanel>

    hope it helps./.

    Tuesday, January 7, 2014 6:34 AM
  • User-439809512 posted

    Thanks for your reply. if we use updatepanel  alert message could not be display. Pls suggest java scritp code to avoid post back

    Tuesday, January 7, 2014 6:37 AM
  • User-760709272 posted

    If you don't want autopostback, don't use an asp:DropDown.  If you want to use asp:DropDown with no page refresh then use an UpdatePanel.  You can't mix and match, it is one or the other.  If your alert isn't working, re-arrange your code so that it does work.  If you put the code that renders the javascript to make the alert happen inside the updatepanel it should work.  But there are lots of reasons as to why your alert might not be working but we'd need to see the code to work out why.  Just wrapping the dropdown in an updatepanel isn't going to solve your problem, you have to work out exactly what the updatepanel has to go around.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 7, 2014 6:42 AM
  • User-1509636757 posted

    alert message could not be display

    Well, we can. Sample Code:

            <asp:ScriptManager runat="server" />
            <asp:UpdatePanel runat="server">
                <ContentTemplate>
                    <asp:DropDownList runat="server" ID="ddlTest" AutoPostBack="true" OnSelectedIndexChanged="ddlTest_SelectedIndexChanged">
                        <asp:ListItem Text="text1" />
                        <asp:ListItem Text="text2" />
                    </asp:DropDownList>
                </ContentTemplate>
            </asp:UpdatePanel>
        protected void ddlTest_SelectedIndexChanged(object sender, EventArgs e)
        {
            ScriptManager.RegisterClientScriptBlock(this, typeof(string), "TestScript", "alert('Sample Alert');", true);
        }



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 7, 2014 7:22 AM