Monday, April 21, 2014

Update label by using jQuery

In this tutorial I will shou you how to change label by using jQuery

we will use jQuery.text() method for this purpose

$("#lblShareError").text("Your new Text");

where lblShareError is the name of our label

I hope it was informative for you, and I would like to Thank You for reading

Clear Textbox text using jQuery

In this tutorial I will show you how you can clear textbox value in jQuery

                $("#<%=TextBoxName.ClientID %>").val("");

To do this is javascript we can use document.getElementById

 document.getElementById('txtFolderName").value = "";

if the control is inside master page and you want to access it  from content page than use the following syntax

document.getElementById('<%=Master.FindControl("txtFolderName").ClientID %>').value = "";


I hope it was informative for you and I would like to Thank you for reading

Sunday, April 20, 2014

Check String length jQuery Custom Validation

In this tutorial I will show you how you can validate string length i.e. maximum and minimum characters in jQuery

For this operation we will use ASP.NET Custom validator

First in our markup we need to create a Custom Validator

<asp:CustomValidator ID="CustomPasswordRangeValidator"
ClientValidationFunction="ClientValidate" ControlToValidate="Password" runat="server"></asp:CustomValidator>

Now we will define a method in javascript this function will contain all the validation

function ValidateUserName(source, clientside_arguments) {
            //Test whether the length of the value is more than 6 characters
            if (clientside_arguments.Value.length >= 4 && clientside_arguments.Value.length <= 10) {
                clientside_arguments.IsValid = true;
            }
            else {
                clientside_arguments.IsValid = false
                source.innerHTML = "UserName must be between 5 to 10 characters";
            };
 
this function check if the string length is greater than 4 and less than 10 than it will be allowed.
 
else we will set a custom error message
 
I hope it was informative for you and I would like to Thank you for reading