The following code does not work. The markup is in User Control, and I assume that why ClientID returns an invalid prefix for the TextBox identifier.
Markup:
<INPUT id="txtName" runat="server" maxlength="50" style="WIDTH:100px"> <INPUT type="button" value="Find Your Doctor" id="btnFind" runat="server" style="MARGIN-LEFT:10px;WIDTH:130px">
Code-Behind:
btnFind.Attributes.Add("onClick",string.Format("DoctorLink ('{0}',document.getElementById('{1}').value,{2});", row["ZipCode"], txtName.ClientID));
Results in the browser:
<input name="DoctorsMainArea1$ctl01$txtName" type="text" id="DoctorsMainArea1_ctl01_txtName" maxlength="50" style="WIDTH:100px" /> <input name="DoctorsMainArea1$ctl01$btnFind" type="button" id="DoctorsMainArea1_ctl01_btnFind" value="Find Your Doctor" style="MARGIN- LEFT:10px;WIDTH:130px" onClick="PrepareDoctorLink('90210', document.getElementById('DoctorsMainArea1_ctl00_txtName').value);" />
As you can see, the parameter for calling JavaScript is DoctorsMainArea1_ctl00_txtName , but the actual identifier of the input element is DoctorsMainArea1_ctl01_txtName .
Any idea how to fix this? Jquery I'm not interested in explaining what is happening (maybe there is another control on this page), but a more reliable way to solve the problem.
cdonner
source share