views:

23

answers:

1

I'm having trouble with this simple scenario.

First, I'm using ASP.NET WebForms.

I'm making an ajax call using jQuery after the user select a value on a first dropdown (select). This call will return me an array of values with which I fill a second DropDownList. After a postback, of course the DropDownList has no items.

I have tried to re-fill the DropDownList in the Init event of the page, but the viewstate has not been processed and I need the selected value of the first DropDownList to get the correct values.

I know that I could probably hack something with putting the selected value of the dropdown inside an hidden field and get it back later in the page cycle, but surely there is something I'm missing? A more easy way (no UpdatePanel solution please).

+1  A: 

With JavaScript/AJAX

You can use PageMethods to get the Data for the second list.

Page Methods are static functions with the [WebMethod] attribute. eg:

  [WebMethod]
  public static string GetHello()
  {
    return "hello";
  }

To see how to do this, you should read the page using-jquery-to-directly-call-aspnet-ajax-page-methods

Without Ajax

  • Enable the CausesPostBack property in the first list.
  • Fill the second drop down list in the SelectedIndexChanged event of the first.
mikek3332002
I'm doing this to "ajaxifying" a web application.
Sebastien Lachance