How to force a postback from code

I have 2 dropdownlists bound to datasources in a 2.0 page.

When the first one changes, the second one does as well because the first control is a parameter in the datasource of the second. When the pages is first loaded, I want to set the value of the first list to a cookie value.

That works, but it isn't causing a postback to update the second list as it does when the user makes a selection. How can I force the first control to do a postback and update the datasource of the second?



Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Select the item and look in the properties pane for "AutoPostBack" and set it to true. That should postback every time the user selects a different item.
Another way to do it is in to add AutoPostBack="True" to your asp:DropDownList tag.

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"> should do it.
why the PageLoad...ControlName.AutoPostBack = true

forgot that one kdtresh...but kdtresh is right and should get points...
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

km5gnAuthor Commented:
Perhaps I wasn't clear. Autopostback is set to true and all works fine when the user makes a selection. It doesn't happen when I set the selection in code. I want it to behave the same way when I set the selection in code as it does when the user makes the selection.
when you do it in code, are you doing it form an event?
If you are doing it from code you will have to manually fire off the event handler.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
If not, you will either have to call an event
One possible solution here:

StringBuilder sbScript = new StringBuilder();

sbScript.Append("<script language='JavaScript' type='text/javascript'>\n");
sbScript.Append(this.GetPostBackEventReference(this, "PBArg") + ";\n");
sbScript.Append("// -->\n");

this.RegisterStartupScript("AutoPostBackScript", sbScript.ToString());

Dim sbScript As New StringBuilder()

sbScript.Append("<script language='JavaScript' type='text/javascript'>" + ControlChars.Lf)
sbScript.Append("<!--" + ControlChars.Lf)
sbScript.Append((Me.GetPostBackEventReference(Me, "PBArg") + ";" + ControlChars.Lf))
sbScript.Append("// -->" + ControlChars.Lf)
sbScript.Append("script>" + ControlChars.Lf)

Me.RegisterStartupScript("AutoPostBackScript", sbScript.ToString())
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.