Thursday, March 3, 2011

How do I add Ajax to my ASPnet page so that a dropdown change can immediately affect the backend db

I have a couple of dropdown boxes on a normal ASP.Net page.

I would like the user to be able to change these and to have the page Pseudo-post back to the server and store these changes without the user having to hit a save button.

I don't really need to display anything additional as the dropdown itself will reflect the new value, but I would like to post this change back without having the entire page flash due to postback

I have heard that this is possible using AJAX.Net...

Can someone point me in the right direction?

From stackoverflow
  • Add a reference to System.Web.Extensions and System.Web.Extensions.Design to your website. Then put a scriptmanager on your page and wrap your ddl in an updatepanel. Do whatever you want on the back-end. For example...

    <asp:ScriptManager ID="ScriptManager1" runat="server" />
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
      <ContentTemplate>
    
    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="yourDDL_SelectedIndexChanged">
    </asp:DropDownList>
    
      </ContentTemplate>
    </asp:UpdatePanel>
    
    protected void yourDDL_SelectedIndexChanged(object sender, EventArgs e)
    {
    // do whatever you want
    }
    
  • Depends upon your Ajax Framework, Ra-Ajax have a sample of that here...

0 comments:

Post a Comment