Thursday, February 9, 2017

Write value to Asp Dot Net Textbox using Javascript

 Hi this post show "How to write Value to Asp Dot Net TextBox using Javascript". Sometimes we face situation like writing client side variable to server side textbox.Lets see how to do it.


Html Tag:

Our sample asp:textbox and button.

<form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server" Text="test" ClientIDMode="Static"></asp:TextBox><br />    
        <button type="button" onclick="Clear()">Write</button>
    </div>
    </form>

Javascript:

<script type="text/javascript">
        function Clear() {
            document.getElementById("<% =TextBox1.ClientID %>").value="How are you?";
        }
    </script>

Output:





No comments:

Post a Comment