Can anyone tell me how to find the value of a control, such as a DropDownList, when using Nested Masterpages?
If I have a DropDownList
<
asp:DropDownList id="myDropDownListID" runat="server"></asp:DropDownList>
in a normal situation, I can retreive the value or selected index by doing myDropDownListID.SelectedIndex or myDropDownList.SelectValue etc. This works fine.
The problem comes when you have your DropDownList in a Web USer Control and/or a Nested MasterPage. The ASP.Net compiler alters the ID of your DropDownlist in order to make the ID totally unique. Due to the fact that the compiler cannot guarantee that the programmer won't insert 2 controls into the same page, it prefixes the DDL ID with the control ID. If this is in a Masterpage it will prefix the Masterpage ID/Name. This means that the control ID will change from myDropDownListID to myWebControlID.myDropDownListID or even myMasterPageID.myWebControlID.myDropDownListID In actual fact the name will change to something more along the lines of ctl00$ctl00$myMasterPageID$myWebControlID$myDropDownListID$ctl09$ctl00. God only knows why the compiler insists on inserting ctl00 etc.
Anyway, back to my actual question:
Does anybody know how I can do the equivalent of myDropDownListID.SelectedIndex without doing ctl00$ctl00$myMasterPageID$myWebControlID$myDropDownListID$ctl09$ctl00.SelectedValue which I simply don't believe is the correct way to do it. I've messed around with Me.FindControl("myDropDownListID") with no luck.
Any ideas as this is driving me crazy? I simply don't believe that as son as you start putting controls inside Masterpages or Web Controls you loose the benefits of beign able to do myDropDownListID.SelectedIndex or whatever. At the moment the only way I can get the value is by using the name of the control which doesnt change i.e. Request.Quesrystring("myDDLName").
Thanks in advance,
Chris