7

I'm trying to use some AJAX and ASP.Net together to enable me to run functions without having to refresh the whole page but i've stumbled across a problem in doing this

Here's my code

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <asp:DropDownList ID="ddl1" runat="server" OnSelectedIndexChanged="update1" />

        <asp:TextBox runat="server" ID="txt1" />

    </ContentTemplate>
</asp:UpdatePanel>

And here's my code behind

 Sub update1(ByVal sender As Object, ByVal e As EventArgs)

    txt1.Text = Now.ToString

End Sub

The event doesn't fire because I don't have AutoPostBack="True" on my ddl but adding that to the ddl will postback the whole page.

Is there a way to avoid using AutoPostBack="True" so that it only updates the panel?

I know I can use an asp:Button to get around this but i'd really like to be able to use a ddl with OnSelectedIndexChanged

Thanks

2
  • r u sure AutoPostBack="True" postback whole page? May 3, 2011 at 10:27
  • 2
    Adding autopostback='true' should not postback the entire page (at least the page won't flickr) - it should just update the contents of the update panel?
    – Paddy
    May 3, 2011 at 10:28

2 Answers 2

7

If you want to avoid to send the whole viewstate to the server, you should look at callbacks.

Instead, if you want to avoid a refresh of the entire page, but with postback, this should work:

<asp:DropDownList ID="ddl1" runat="server" OnSelectedIndexChanged="update1" AutoPostBack="True"  />

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <Triggers>
         <asp:AsyncPostbackTrigger ControlID="ddl1" EventName="SelectedIndexChanged" />
    </Triggers>
    <ContentTemplate>
        <asp:TextBox runat="server" ID="txt1" />
    </ContentTemplate>
</asp:UpdatePanel>
2
  • AutoPostBack="True". Thanks. I hate using UpdatePanels (I prefer JQuery) so I feel like I'm going back in time. But this is what I needed today. Upvote. Mar 12, 2013 at 15:07
  • Why this answer isn't given everywhere else with a similar question has been asked is completely beyond me. Exactly what I was looking for. Thanks. Oct 1, 2014 at 15:43
0

Try creating a new page with same codes and different page name. Worked for me

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.