I have a dropdownlist (on Page) which has OnSelectedIndexChange event thats Loads different Control (ascx) dynamically each time ( with LoadControl Command) – into the page.
Each Control Has a Button(runat=server) and TextBox(runat=server).
When i click on the button – i cant get into the Onclick function .
How can i get into the OnClick Function of the Ascx ?
I know that each SelectedIndexChange its makes postback – so i know i have to save something in the viewstate. but i dont know how to save it and later get the values eneterd on the TexstBox. ( of Each ascx)
You need to add an event handler to the user control, like this:
And in the click event of the button:
Then, from the page, you can get the click event like this:
If you’re loading the controls dynamically, then you’ll need to make sure the controls are rehydrated after postback, and emulate the code above by assinging the event handler through code: