This is a migrated thread and some comments may be shown as answers.

Find Control Serverside in FormTemplate

2 Answers 272 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nick
Top achievements
Rank 1
Nick asked on 11 May 2009, 03:49 PM
Hi,
I have a RadioButtonList as part of my FormTemplate.  When the index of this changes, I want to do some server-side processing & change the value of a label that is also in the Form Template.  So, I have set up within the FormTemplate
<asp:RadioButtonList ID="rdo1" runat="server" 
 Onselectedindexchanged="rdo1_SelectedIndexChanged" AutoPostBack="True"
</asp:RadioButtonList> 

And in the code behind:
protected void rdo1_SelectedIndexChanged(object sender, EventArgs e) { 
RadioButtonList rdoList = this.RadGrid1.FindControl("rdo1"as RadioButtonList; 
Label lbl = this.RadGrid1.FindControl("lbl1"as Label; 

But they are never found and my Controls are set to null;  Any help/suggestions?  I've seen the client-side solution to this, but I would prefer to not do this on the client.
Thanks.


2 Answers, 1 is accepted

Sort by
0
Nick
Top achievements
Rank 1
answered on 11 May 2009, 04:09 PM
Ok, I jumped the gun and figured it out.  In case anyone else had this issue, here is what worked for me:
protected void rdo1_SelectedIndexChanged(object sender, EventArgs e) {  
RadioButtonList rdoList = sender as RadioButtonList;  
Label lbl = rdoList.Parent.FindControl("lbl1");  
}  

duh.



0
KC
Top achievements
Rank 1
answered on 08 May 2014, 05:31 PM
Thank *you*, Nick!  "Parent" is not a 'duh' when you don't know about it.  You've saved me hours of time wondering why searching from the presumed parent control never seemed to work for me.  Thank you. Again.
Tags
Grid
Asked by
Nick
Top achievements
Rank 1
Answers by
Nick
Top achievements
Rank 1
KC
Top achievements
Rank 1
Share this question
or