findControl & checkbox state
-
Hello, I'm programming in .net enviroment (asp.net in c#). i would like to ask two seperate questions: question 1 I would like to find control in a form during run-time using "this.Page.FindControl("ctl")" the problem is that the control is nested somewhere inside (i.e inside panels or place holders) thus when running the above command i recieve nothing. how can i find the control? must i create a function that loop on the controls of the page and when it reachs a control that has container, it searches inside (recursive)? is it not bad for performances? question 2 I have a photo gallery divided into pages. the pictures are shown in DataList. Above each photo i have a checkbox which alow the user to select it. When moving between pages I would like the application to "remember" the checkbox that were chosen for two reasons: 1. when the user return to a page were several photos were selected, their checkbox will be checked. 2. when the user press a "send" button, a list of all the photos will be send (not only those that are shown on the current page). Please advice how to do so. Eran Sakal.
-
Hello, I'm programming in .net enviroment (asp.net in c#). i would like to ask two seperate questions: question 1 I would like to find control in a form during run-time using "this.Page.FindControl("ctl")" the problem is that the control is nested somewhere inside (i.e inside panels or place holders) thus when running the above command i recieve nothing. how can i find the control? must i create a function that loop on the controls of the page and when it reachs a control that has container, it searches inside (recursive)? is it not bad for performances? question 2 I have a photo gallery divided into pages. the pictures are shown in DataList. Above each photo i have a checkbox which alow the user to select it. When moving between pages I would like the application to "remember" the checkbox that were chosen for two reasons: 1. when the user return to a page were several photos were selected, their checkbox will be checked. 2. when the user press a "send" button, a list of all the photos will be send (not only those that are shown on the current page). Please advice how to do so. Eran Sakal.
esakal wrote: I'm programming in .net enviroment (asp.net in c#). Then use the ASP.NET forum for that :) xacc-ide 0.0.15 now with C#, MSIL, C, XML, ASP.NET, Nemerle, MyXaml and HLSL coloring - Screenshots
-
Hello, I'm programming in .net enviroment (asp.net in c#). i would like to ask two seperate questions: question 1 I would like to find control in a form during run-time using "this.Page.FindControl("ctl")" the problem is that the control is nested somewhere inside (i.e inside panels or place holders) thus when running the above command i recieve nothing. how can i find the control? must i create a function that loop on the controls of the page and when it reachs a control that has container, it searches inside (recursive)? is it not bad for performances? question 2 I have a photo gallery divided into pages. the pictures are shown in DataList. Above each photo i have a checkbox which alow the user to select it. When moving between pages I would like the application to "remember" the checkbox that were chosen for two reasons: 1. when the user return to a page were several photos were selected, their checkbox will be checked. 2. when the user press a "send" button, a list of all the photos will be send (not only those that are shown on the current page). Please advice how to do so. Eran Sakal.
for question 1, are you searching for a Control whose Id value you set at design-time? that is, can you use
document.getElementById(knownControlId)
in client-side javascript? for question2, I'd try using<input type="hidden" id="ipt_[associated Image Id]" value="false" />
then use script (I'm big on client-side script) to handle the checkbox onclick event.function checkboxClicked(checkBox){
var sId = checkBox.id;
if (sId){
// use a naming convention to convert to the id of the input
var inputElem = document.getElementById(sId);
if (inputElem && inputElem.value) {
inputElem.value = "true";
}
}
}
Then add
onclick="checkBoxClicked(this);"
for each checkbox. This approach, although it relies on a naming convention, allows you to have access to the information on both server and client side. HTH