How to force a postback from code

I have 2 dropdownlists bound to datasources in a 2.0 asp.net 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?

TIA,

Steve

km5gnAsked:
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.

kdtreshCommented:
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.
0
kdtreshCommented:
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.
0
silemoneCommented:
why not...in the PageLoad...ControlName.AutoPostBack = true

forgot that one kdtresh...but kdtresh is right and should get points...
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

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.
0
silemoneCommented:
when you do it in code, are you doing it form an event?
0
BTosonCommented:
If you are doing it from code you will have to manually fire off the event handler.
0

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
silemoneCommented:
If not, you will either have to call an event
0
kdtreshCommented:
One possible solution here: http://forums.asp.net/t/928411.aspx

C#:
----
StringBuilder sbScript = new StringBuilder();

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

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

VB:
----
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("</")
sbScript.Append("script>" + ControlChars.Lf)

Me.RegisterStartupScript("AutoPostBackScript", sbScript.ToString())
0
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
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.