I want to check the username availbilty so I have this code:
<script type = "text/javascript">
function ShowAvailability() {
$.ajax({
type: "POST",
url: "Default.aspx/CheckUserName",
data: '{userName: "' + $("#<%=UserName.ClientID%>")[0].value + '" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {
alert(response);
}
});
}
function OnSuccess(response) {
var mesg = $("#mesg")[0];
switch (response.d) {
case "true":
mesg.style.color = "green";
mesg.innerHTML = "Available";
break;
case "false":
mesg.style.color = "red";
mesg.innerHTML = "Not Available";
break;
case "error":
mesg.style.color = "red";
mesg.innerHTML = "Error occured";
break;
}
}
function OnChange(txt) {
$("#mesg")[0].innerHTML = "";
}
</script>
In general we write this way to get the required clientID
$("#<%=UserName.ClientID%>")
Now I need to get the Username textbox Client ID as I am using create user wizard. How do I do in this case?
I have tried this but I'm getting error as 'TextBox' is a type and cannot be used as an expression.
var UserName = '<%= ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("UserName")).ClientID %>';
Try this
var UserName = '<%= ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("UserName")).ClientID %>';