Put value in Asp.net textbox from javascript

In this blog we will know how to put value in asp.net textbox from JavaScript.

 

Method-1

 

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Get_value_Textbox_javascript._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 runat="server">

    <title>Untitled Page</title>

    <script type="text/javascript">

    document.getElementById('<%=Test.ClientID%>').value;

    </script>

</head>

<body>

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

    <div>

    <asp:TextBox id="Test" Text="Welcome" runat="server"/>

    </div>

    </form>

</body>

</html>

 

Method-2

 

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Get_value_Textbox_javascript._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 runat="server">

    <title>Untitled Page</title>

    <script type="text/javascript">

    document.forms[0]['Test'].value;

    </script>

</head>

<body>

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

    <div>

    <asp:TextBox id="Test" Text="Welcome" runat="server"/>

    </div>

    </form>

</body>

</html>

 

 

 

Ebook Download
View all
Learn
View all