Trying to find controls within edit form fails every time
<telerik:RadAjaxPanel ID=
"rpNotes"
runat=
"server"
LoadingPanelID=
"RadAjaxLoadingPanel1"
>
<telerik:RadGrid ID=
"rgNotes"
runat=
"server"
GroupPanelPosition=
"Top"
OnItemCommand=
"rgNotes_ItemCommand"
>
<GroupingSettings CollapseAllTooltip=
"Collapse all groups"
></GroupingSettings>
<MasterTableView NoDetailRecordsText=
"No notes for this Appointment"
AutoGenerateColumns=
"False"
DataKeyNames=
"notes_id"
CommandItemDisplay=
"Top"
CommandItemSettings-AddNewRecordText=
"Add Notes"
AllowAutomaticInserts=
"true"
EditMode=
"PopUp"
>
<Columns>
<telerik:GridEditCommandColumn UniqueName=
"EditCommandColumn"
>
</telerik:GridEditCommandColumn>
<telerik:GridBoundColumn DataField=
"notes_id"
FilterControlAltText=
"Filter notes_id column"
HeaderText=
"notes_id"
ReadOnly=
"True"
SortExpression=
"notes_id"
Visible=
"true"
UniqueName=
"notes_id"
>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField=
"Subject"
FilterControlAltText=
"Filter Subject column"
HeaderText=
"Subject"
ReadOnly=
"True"
SortExpression=
"Subject"
UniqueName=
"Subject"
>
</telerik:GridBoundColumn>
</Columns>
<EditFormSettings EditFormType=
"Template"
InsertCaption=
"Add new Note"
CaptionFormatString=
"Please enter or update note"
>
<FormTemplate>
<telerik:RadTextBox ID=
"txtNotesId"
Visible=
"false"
Width=
"200px"
runat=
"server"
></telerik:RadTextBox>
Subject
<p>
<telerik:RadTextBox ID=
"txtSubjectNotes"
Width=
"200px"
runat=
"server"
></telerik:RadTextBox>
</p>
<p>
Notes<br />
<telerik:RadTextBox ID=
"txtMultiNotes"
TextMode=
"MultiLine"
Rows=
"10"
Columns=
"10"
Width=
"200px"
runat=
"server"
></telerik:RadTextBox>
</p>
<telerik:RadButton ID=
"rdSaveNotes"
OnClick=
"rdSaveNotes_Click"
Skin=
"Bootstrap"
BackColor=
"#512479"
ForeColor=
"White"
runat=
"server"
Text=
"Save Notes"
></telerik:RadButton>
<telerik:RadButton ID=
"rdCancel"
OnClick=
"rdCancel_Click1"
CommandName=
"Cancel"
Skin=
"Bootstrap"
BackColor=
"#512479"
ForeColor=
"White"
runat=
"server"
Text=
"Cancel"
></telerik:RadButton>
</FormTemplate>
</EditFormSettings>
</MasterTableView>
<ClientSettings>
<ClientEvents OnPopUpShowing=
"PopUpShowing"
/>
<Selecting AllowRowSelect=
"true"
/>
</ClientSettings>
</telerik:RadGrid>
</telerik:RadAjaxPanel>
I am using this function here which i found on stackoverflow
/// <summary>
/// Recursively searches for a server control with the given ID.
/// </summary>
/// <param name="id">ID of control to find</param>
/// <returns>The matching control or null if no match was found</returns>
public
static
Control FindControlRecursive(
this
Control control,
string
id)
{
if
(control ==
null
)
return
null
;
//try to find the control at the current level
Control ctrl = control.FindControl(id);
if
(ctrl ==
null
)
{
//search the children
foreach
(Control child
in
control.Controls)
{
ctrl = FindControlRecursive(child, id);
if
(ctrl !=
null
)
break
;
}
}
return
ctrl;
}
And this is how i use it
// TextBox txtSubjectNotes = (TextBox)item.FindControl("txtSubjectNotes");
// TextBox txtMultiNotes = (TextBox)item.FindControl("txtMultiNotes");
//add custom logic here
RadTextBox ctrl = (RadTextBox)
this
.FindControlRecursive(
"txtSubjectNotes"
);
RadTextBox myControl;
if
(ctrl
is
RadTextBox)
{
myControl = (RadTextBox)
this
.FindControlRecursive(
"txtSubjectNotes"
);
// _note.note = txtMultiNotes.Text;
_note.subject = myControl.Text;
}