Saturday, March 24, 2012

Exclude page_load during ajax content pannel update possible?

I have this in my behind:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
DropDownList1.SelectedIndex = DropDownList1.Items.IndexOf(DropDownList1.Items.FindByText(String.Format("{0:yyyy}", DateTime.Now).ToString()))
End Sub

The problem is, whenever I select a new value in my drop down list, it defaults itself back to the current month. Is there a way to exclude this from running when I am using an ajax update panel?

You can use Page.IsPostback for this. It is false for the very first request, and true for any postback (also true for async postback)

If you need to determine whether you have a full or an async postback, you can use:IsInAsyncPostBack


If anyone was curious as to how the syntax looked here it is. Worked like a charm. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If (Page.IsPostBack = False) Then DropDownList1.SelectedIndex = DropDownList1.Items.IndexOf(DropDownList1.Items.FindByText(String.Format("{0:yyyy}", DateTime.Now).ToString())) End If End Sub

No comments:

Post a Comment