I am trying to validate an asp textbox via javascript but I can't get the javascript code to validate the textbox control. Textbox markup in the usercontrol: Here is my code in the page load event that register the javascript code block Dim cs As ClientScriptManager = Page.ClientScript
If Not cs.IsClientScriptBlockRegistered(csType, csEmailCheck) Then
Dim csText As New StringBuilder()
csText.Append(Environment.NewLine + "[script removed]
csText.Append(Environment.NewLine + "function CheckSubject(){")
csText.Append(Environment.NewLine + " if (document.getElementById(""<%=txtEmailSubject.ClientID%>"").value=="""")")
csText.Append(Environment.NewLine + " {")
csText.Append(Environment.NewLine + " var answer = confirm (""Do you want to send an email without a subject?"")")
csText.Append(Environment.NewLine + " if (answer)")
csText.Append(Environment.NewLine + " return true;")
csText.Append(Environment.NewLine + " else")
csText.Append(Environment.NewLine + " return false;")
csText.Append(Environment.NewLine + "}")
csText.Append(Environment.NewLine + "}")
csText.Append(Environment.NewLine + "[script removed]")
Page.ClientScript.RegisterClientScriptBlock(csType, csEmailCheck, csText.ToString())
End If
btnSendMail.Attributes.Add("onclick", "return CheckSubject()")
The javascript output is below <script type="text/javascript">
function CheckSubject(){
if (document.getElementById("<%=txtEmailSubject.ClientID%>").value=="")
{
var answer = confirm ("Do you want to send an email without a subject?")
if (answer)
return true;
else
return false;
}
}
script> I know the problem is related to the way dnn names the controls when they are rendered to the page. Any suggestions? Thank you |