Skip to main content
deleted 1 character in body
Source Link
nbi
  • 785
  • 2
  • 10
  • 27

I want to get the value of textbox that a user enters. Below is the code snippet of aspx page :

<asp:TextBox id="txtUserName" runat="server" />

Now which is the best way to access DOM object in aspx page

1.

<script type="text/javascript">
var value= document.getElementById(<%= txtUserName.ClientID %>).value;
alert(value);
</script>
<script type="text/javascript">
var value= document.getElementById(<"txtUserName""txtUserName").value;
alert(value);
</script>

I want to get the value of textbox that a user enters. Below is the code snippet of aspx page :

<asp:TextBox id="txtUserName" runat="server" />

Now which is the best way to access DOM object in aspx page

1.

<script type="text/javascript">
var value= document.getElementById(<%= txtUserName.ClientID %>).value;
alert(value);
</script>
<script type="text/javascript">
var value= document.getElementById(<"txtUserName").value;
alert(value);
</script>

I want to get the value of textbox that a user enters. Below is the code snippet of aspx page :

<asp:TextBox id="txtUserName" runat="server" />

Now which is the best way to access DOM object in aspx page

1.

<script type="text/javascript">
var value= document.getElementById(<%= txtUserName.ClientID %>).value;
alert(value);
</script>
<script type="text/javascript">
var value= document.getElementById("txtUserName").value;
alert(value);
</script>
Source Link
nbi
  • 785
  • 2
  • 10
  • 27

correct or efficient way of accessing DOM object in aspx pages

I want to get the value of textbox that a user enters. Below is the code snippet of aspx page :

<asp:TextBox id="txtUserName" runat="server" />

Now which is the best way to access DOM object in aspx page

1.

<script type="text/javascript">
var value= document.getElementById(<%= txtUserName.ClientID %>).value;
alert(value);
</script>
<script type="text/javascript">
var value= document.getElementById(<"txtUserName").value;
alert(value);
</script>