Thursday, 10 September 2015

Get the data from server controls using javascript in asp.net


  • Today I'll show you how to retrieve the server controls data easily using Javascript in ASP.NET.
  • Normally people I have seen use to retrieve the data from controls is using  something like this:
function validate()
{
     var text=document.getElementById('<%=TextBox1.ClientId%>').value;
   // do stuffs
}

  • And then more code for if you want dropdownlist data and some other controls.
  • Instead simply one can use String function as (e.g. for DropDownList):

function validate()
{
     var text=String('<%=DropDownList1.SelectedItem.Text%>');
     var  value=String('<%=DropDownList1.SelectedItem.Value%>');
   // do stuffs
}

  • That was for this blog have a great day. And yes any one having difficulty can comment anytime.

No comments:

Post a Comment

How To Pass An Array As A Parameter While Calling an ASP.NET Web API C#

Please visit my C# Corner Blog for this, where I have provided better efforts to make this concept more understandable - www.c-sharpcorner....