Tuesday, March 11, 2014

Get Asp.net Textbox value using javascript | Get Server Controls value using javascript

Here I will happy to illustrate how to get asp.net textbox value using JavaScript or get asp.net controls like Label ,Gridview value using JavaScript.

Get Asp.net Textbox, Label and GridView Value using JavaScript

To get asp.net textbox, label, GridView value using JavaScript we need to write a code like as below

Get Textbox value

var UserName = document.getElementById("<%=txtUserName.ClientID %>").value;


Get Label value

var Birthdate = document.getElementById("<%=lblBirthDate.ClientID %>").innerHTML;


Get GridView value

var GridView = document.getElementById("<%=gvData.ClientID %>");

 //check if gridview rows count is more than zero or not
 if (GridView.rows.length > 0) 
   {
       //do something if gridview rows count > 0
   }
else
  {
      //do something if gridview rows count < 0
  } 

No comments:

Post a Comment