Asp.net Clientid

Asp.net Clientid

Here in this post we will see how we can get clientID of an ASp.net server side control at client end.

for demo purpose I have created simple page that contains Asp.net TextBox web control and one html submit button.
On click event of submit button I'm calling Javascript function called xx() that displays value entered in TextBox control

'<%=TextBox1.ClientID%>'  This way we will get Server side control clientId.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" >

<head>

<title>Untitled Page</title>

<script>

function xx()

{

var msg = document.getElementById('<%=TextBox1.ClientID%>').value;

alert(msg);

}

</script>

 

</head>

<body>

<form id="form1" runat="server">

<div>

<asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox></div>

<input id="Submit1" type="submit" value="submit" onclick="xx();" />

</form> </body>

</html>


Tags:

Asp.net Interview Questions for 2 years or 3 years experianceasp net image uploadASp.net 2.0 step by step Membership Provider ASP.net File HandlingJQuery Set Value of Textbox or Label Control In Asp.netWhat is web garden in Asp.net?Asp.net Convert String To ImageAsp.net Convert Image To Base64Hack asp.netAsp.net open new windowListBox Asp.net Binding csharp

Author

My name is Satalaj, but people call me Sat. Here is my homepage: . I live in Pune, PN and work as a Software Engineer. I'm former MVP in ASP.net year 2010.
Disclaimer: Views or opinion expressed here are my personal research and it has nothing to do with my employer. You are free to use the code, ideas/hints in your projects. However, you should not copy and paste my original content to other web sites. Feel free to copy or extend the code.
If you want to fight with me, this website is not for you.
 

I'm Satalaj.