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>
Currently rated 5.0 by 2 people
- Currently 5/5 Stars.
- 1
- 2
- 3
- 4
- 5