This sounds and is so trivial that it is well hidden in the docs.
On my form is a datalist with in each row a label and a radiobuttonlist. On the radiobuttonlist autopostback is set to true, selecting another radiobutton will lead to a roundtrip. The items of a datalist are templates so there are no codebehind eventhandler for the controls. But my code needs to know which row of the datalist triggered the postback. This is a part of the HTML rendered:
<span id="DataList1__ctl11_Label1" style="height:1px;width:336px;">Wijzigingen in het suiker en specialiteiten gebouw, hygiënische ruimten of installaties voor opslag van produktspan>
<span id="DataList1__ctl11_RadioButtonListAntwoord" style="height:5px;width:142px;"><input id="DataList1__ctl11_RadioButtonListAntwoord_0" type="radio" name="DataList1:_ctl11:RadioButtonListAntwoord" value="1" onclick="__doPostBack('DataList1__ctl11_RadioButtonListAntwoord_0','')" language="javascript" />
<label for="DataList1__ctl11_RadioButtonListAntwoord_0">Jalabel><input id="DataList1__ctl11_RadioButtonListAntwoord_1" type="radio" name="DataList1:_ctl11:RadioButtonListAntwoord" value="2" onclick="__doPostBack('DataList1__ctl11_RadioButtonListAntwoord_1','')" language="javascript" />
<label for="DataList1__ctl11_RadioButtonListAntwoord_1">Neelabel><input id="DataList1__ctl11_RadioButtonListAntwoord_2" type="radio" name="DataList1:_ctl11:RadioButtonListAntwoord" value="3" onclick="__doPostBack('DataList1__ctl11_RadioButtonListAntwoord_2','')" language="javascript" /><label for="DataList1__ctl11_RadioButtonListAntwoord_2">?label>span>
Every radiobutton has a snippet of script which takes the control's ID as a parameter. The script function invoked is also in the HTML, it is the __doPostBack function found in every asp.net webform
function __doPostBack(eventTarget, eventArgument) {
var theform;
if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
theform = document.forms["ProjektWegwijzer"];
}
else {
theform = document.ProjektWegwijzer;
}
theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
theform.__EVENTARGUMENT.value = eventArgument;
theform.submit();
}
It copies the (cleaned) name of the control into a form member. The contents of this form member can be read in the code behind.
char[] splitters = {'_'};
string[] pbCtrl = Request.Form["__EVENTTARGET"].Split(splitters);
// Index of control ID's is 1-based !
int lIndex = int.Parse(pbCtrl[2].Substring(3)) - 1;
int aw = int.Parse(pbCtrl[4]);
The ID of all the radibuttons have a format like DataList1__ctlxx_RadioButtonListAntwoord_y. In it xx will return the datalist row which triggered the callback and yy the index of the radiobutton.
Peter