I can't access any of my controls or their properties that are within my ReorderList Templates. Is this a normal behaviour for the ReorderList or I am I doing something wrong?
I tried .FindControl() and it doesn't seem to find them either.
Heres the markup for the reorderlist.
<cc1:ReorderListID="ReorderList1"runat="server"AllowReorder="True"Height="10px"PostBackOnReorder="False"ItemInsertLocation="End"ShowInsertItem="True"SortOrderField="DependOrder"DataKeyField="AutoID"Width="895px"><ItemTemplate><divclass="itemArea"><tablecellpadding="1"cellspacing="0"><tr><tdstyle="height: 13px;"><tableborder="0"cellpadding="0"cellspacing="0"><tr><td><asp:ImageButtonID="btnEdit"runat="server"ImageUrl="~/img/Edit.gif"CausesValidation="False"CommandName="Edit"/></td><tdstyle="width: 17px"><asp:ImageButtonID="ImageButton3"runat="server"CommandName="Delete"ImageUrl="~/img/Delete.gif"CausesValidation="False"/></td><tdstyle="width: 17px"><asp:ImageButtonID="ImageButton1"runat="server"CommandName="Edit"ImageUrl="~/img/View.gif"CausesValidation="False"/></td></tr></table></td><tdstyle="width: 10%; height: 13px;"><asp:LabelID="Label1"runat="server"ForeColor="black"Text="<%# ((HelpDesk.Task)Container.DataItem).AutoID %>"></asp:Label></td><tdstyle="width: 30%; height: 13px;"><asp:LabelID="Label2"runat="server"Text="<%# ((HelpDesk.Task)Container.DataItem).TaskName %>"></asp:Label></td><tdstyle="width: 30%; height: 13px;"><asp:LabelID="Label3"runat="server"Text="<%# ((HelpDesk.Task)Container.DataItem).AssignedTo %>"></asp:Label></td><tdstyle="width: 30%; height: 13px;"><asp:LabelID="Label4"runat="server"Text="<%# ((HelpDesk.Task)Container.DataItem).DueDate %>"></asp:Label></td></tr></table></div></ItemTemplate><DragHandleTemplate><divclass="dragStyle"><asp:Imagerunat="server"ImageUrl="./img/move6.jpg"/></div></DragHandleTemplate><ReorderTemplate><asp:PanelID="pnl2"runat="server"BackColor="Aqua"CssClass="reOrder"Height="40px"></asp:Panel></ReorderTemplate><EditItemTemplate><divclass="itemArea"><tableborder="0"cellpadding="0"cellspacing="0"><tr><tdstyle="width: 17px; height: 22px"></td><tdstyle="width: 21px; height: 22px"></td><tdalign="right"style="width: 101px; height: 22px">
Task:
</td><tdcolspan="5"style="width: 21px; height: 22px"><asp:DropDownListID="ddlTaskEMode"runat="server"DataSourceID="tblTask"DataTextField="TaskName"DataValueField="AutoID"></asp:DropDownList></td><tdcolspan="1"style="width: 21px; height: 22px"></td><tdstyle="width: 100px; height: 22px"></td></tr><tr><tdstyle="width: 17px; height: 168px"></td><tdstyle="width: 21px; height: 168px"></td><tdalign="right"style="width: 101px; height: 168px">
Note:
</td><tdcolspan="5"style="width: 21px; height: 168px"><asp:TextBoxID="txtNotesEMode"runat="server"Height="162px"Width="374px"></asp:TextBox></td><tdcolspan="1"style="width: 21px; height: 168px"></td><tdstyle="width: 100px; height: 168px"></td></tr><tr><tdstyle="width: 17px; height: 17px"></td><tdstyle="width: 21px; height: 17px"></td><tdalign="right"style="width: 101px; height: 17px">
Due Date:
</td><tdcolspan="3"style="width: 1px; height: 17px"><asp:TextBoxID="txtDueDateEditEMode"runat="server"ReadOnly="True"Width="146px"></asp:TextBox> </td><tdcolspan="1"style="height: 17px; width: 17px;"><imgid="Img2"src="img/calendar.gif"style="cursor: hand"/></td><tdstyle="width: 477px; height: 17px"><asp:ImageButtonID="btnReminderEMode"runat="server"ImageUrl="./img/Reminder.gif"OnClientClick="PopupReminder(700,500)"/></td></tr><tr><tdstyle="width: 17px; height: 42px"></td><tdstyle="width: 21px; height: 42px"></td><tdalign="right"style="width: 101px; height: 42px">
Dependancy:
</td><tdcolspan="1"style="width: 16px; height: 42px"><asp:RadioButtonListID="DependOrderEMode"runat="server"AutoPostBack="True"RepeatDirection="Horizontal"Width="152px"><asp:ListItemSelected="True">None</asp:ListItem><asp:ListItem>Order</asp:ListItem></asp:RadioButtonList></td><tdcolspan="5"style="width: 21px; height: 42px"><asp:TextBoxID="txtDependOrderEMode"runat="server"Enabled="False"Width="46px"></asp:TextBox></td><tdcolspan="1"style="width: 21px; height: 42px"></td><tdcolspan="1"style="width: 192px; height: 42px"></td><tdstyle="width: 100px; height: 42px"></td></tr><tr><tdstyle="width: 17px; height: 24px"><asp:ImageButtonID="btnSaveTaskEMode"runat="server"ImageUrl="./img/Save.gif"CausesValidation="False"OnClick="btnSaveTask_Click"/></td><tdstyle="width: 21px; height: 24px"><asp:ImageButtonID="btnUndoTaskEMode"runat="server"ImageUrl="./img/Undo.gif"CausesValidation="False"CommandName="Cancel"OnClick="btnUndoTaskEMode_Click"/></td><tdalign="right"style="width: 101px; height: 24px">
Assigned To:
</td><tdcolspan="3"style="width: 21px; height: 24px"><asp:TextBoxID="txtuserIDEMode"runat="server"></asp:TextBox></td><tdcolspan="1"style="height: 24px; width: 17px;"><asp:ImageButtonID="btnFindUserEMode"runat="server"ImageUrl="./img/binoculars.gif"OnClientClick="PopupUserMdp('userID',620,400)"/></td><tdstyle="width: 477px; height: 24px"> <asp:HiddenFieldID="userIDEMode"runat="server"/></td><tdstyle="width: 100px; height: 24px"></td></tr></table></div></EditItemTemplate><InsertItemTemplate> <asp:PanelID="DropInsert"runat="server"Height="30px"Width="85%"BackColor="#5D7B9D"ForeColor="White"><divstyle="padding:5px; vertical-align:middle; width:95%"><divstyle="float:left"><asp:LabelID="Label5"style="cursor:pointer"runat="server"Text="Insert New Task"></asp:Label> </div><divstyle="float:right; margin-left:40px"><asp:ImageID="Image2"runat="server"style="cursor:pointer"ImageUrl="./img/expand_blue.jpg"/></div></div></asp:Panel><asp:PanelID="pnlInsertTask"runat="server"Height="227px"Style="background-color: #ffff99"Width="439px"BorderStyle="None"BorderWidth="0px"><p> <tableborder="0"cellpadding="0"cellspacing="0"style="width: 454px"><tr><tdstyle="width: 17px; height: 22px"></td><tdstyle="width: 21px; height: 22px"></td><tdalign="right"style="width: 101px; height: 22px">
Task:
</td><tdcolspan="5"style="width: 21px; height: 22px"><asp:DropDownListID="ddlTask"runat="server"DataSourceID="tblTask"DataTextField="TaskName"DataValueField="AutoID"></asp:DropDownList></td><tdcolspan="1"style="width: 21px; height: 22px"></td><tdstyle="width: 100px; height: 22px"></td></tr><tr><tdstyle="width: 17px; height: 168px"></td><tdstyle="width: 21px; height: 168px"></td><tdalign="right"style="width: 101px; height: 168px">
Note:
</td><tdcolspan="5"style="width: 21px; height: 168px"><asp:TextBoxID="txtNotes"runat="server"Height="160px"Width="374px"></asp:TextBox></td><tdcolspan="1"style="width: 21px; height: 168px"></td><tdstyle="width: 100px; height: 168px"></td></tr><tr><tdstyle="width: 17px; height: 17px"></td><tdstyle="width: 21px; height: 17px"></td><tdalign="right"style="width: 101px; height: 17px">
Due Date:
</td><tdcolspan="3"style="width: 1px; height: 17px"><asp:TextBoxID="txtDueDateEdit"runat="server"ReadOnly="True"Width="146px"></asp:TextBox> </td><tdcolspan="1"style="height: 17px; width: 17px;"><imgid="Img1"src="img/calendar.gif"style="cursor: hand"/></td><tdstyle="width: 477px; height: 17px"><asp:ImageButtonID="btnReminder"runat="server"ImageUrl="./img/Reminder.gif"OnClientClick="PopupReminder(700,500)"/></td></tr><tr><tdstyle="width: 17px; height: 42px"></td><tdstyle="width: 21px; height: 42px"></td><tdalign="right"style="width: 101px; height: 42px">
Dependancy:
</td><tdcolspan="1"style="width: 16px; height: 42px"><asp:RadioButtonListID="RadioButtonList1"runat="server"AutoPostBack="True"RepeatDirection="Horizontal"Width="152px"><asp:ListItemSelected="True">None</asp:ListItem><asp:ListItem>Order</asp:ListItem></asp:RadioButtonList></td><tdcolspan="5"style="width: 21px; height: 42px"><asp:TextBoxID="txtDependOrder"runat="server"Enabled="False"Width="46px"></asp:TextBox></td><tdcolspan="1"style="width: 100px; height: 42px"></td><tdcolspan="1"style="width: 192px; height: 42px"></td><tdstyle="width: 100px; height: 42px"></td></tr><tr><tdstyle="width: 17px; height: 24px"><asp:ImageButtonID="btnSaveTask"runat="server"ImageUrl="./img/Save.gif"CausesValidation="False"OnClick="btnSaveTask_Click"/></td><tdstyle="width: 21px; height: 24px"><asp:ImageButtonID="btnUndoTask"runat="server"ImageUrl="./img/Undo.gif"CausesValidation="False"OnClick="btnUndoTask_Click"/></td><tdalign="right"style="width: 101px; height: 24px">
Assigned To:
</td><tdcolspan="3"style="width: 21px; height: 24px"><asp:TextBoxID="txtuserID"runat="server"></asp:TextBox></td><tdcolspan="1"style="height: 24px; width: 17px;"><asp:ImageButtonID="btnFindUser"runat="server"ImageUrl="./img/binoculars.gif"OnClientClick="PopupUserMdp('userID',620,400)"/></td><tdstyle="width: 477px; height: 24px"> <asp:HiddenFieldID="userID"runat="server"/></td><tdstyle="width: 100px; height: 24px"></td></tr></table> <cc1:CalendarExtenderID="CalendarExtender1"runat="server"Format="MMM-dd-yyyy"PopupButtonID="Img1"TargetControlID="txtDueDateEdit"></cc1:CalendarExtender><cc1:CollapsiblePanelExtenderID="CollapsiblePanelExtender1"runat="server"AutoCollapse="false"AutoExpand="false"Collapsed="true"CollapseControlID="DropInsert"ExpandControlID="DropInsert"CollapsedImage="img/expand_blue.jpg"ExpandedImage="./img/collapse_blue.jpg"ImageControlID="image2"TargetControlID="pnlInsertTask"></cc1:CollapsiblePanelExtender> </p></asp:Panel> </InsertItemTemplate></cc1:ReorderList>
Please recall that each controls' ClientID will be prefixed with a parent control ID... namely "ReorderList1__rliX_"
where X is the line item number of the list item. They will be prefixed more depending on how many parent controls they are in.
How are you trying to find them? Obviously specifying "RadioButtonList1" , for example, simply won't work.
It would be useful to know what control you are trying to access, and during what event.
In the code behind I am trying to grab the textbox value for example.
so something like this
private void btnSave_Click(object sender,EventArgs e)
{
string notes = txtNotes.Text
//Insert notes into Data Table
}
Error 1 The name 'txtNotes' does not exist in the current context.
And something like this
string
s = ((TextBox)ReorderList1.FindControl("ctl00_ContentPlaceHolder1_ReorderList1__rliInsert_txtNotes")).Text
comes back cant find the control.
Try this:
First of all btnSave_Click should be a protected method, not private.
code:
1protected void btnSave_Click(object sender, EventArgs e)2{3TextBox tb = (TextBox)ReorderList1.FindControl("_rliInsert").FindControl("txtNotes");4String s = tb.Text;5}
I hope this helps! (Please mark my post as the solution if this works for you)
Thank you that works!
Just wondering if there is a better way than hardcoding all the control names.
Not that I know of. You can also do it by index (I don't know if these are the actual indexes of your controls).
1protected void btnSave_Click(object sender, EventArgs e)2{3TextBox tb = (TextBox)ReorderList1.Controls[4].Controls[2];4String s = tb.Text;5}
It seems more reliable to me to use the name since the addition of a single control could throw off all your indexes.