简体   繁体   中英

Cannot able to set text box value using javascript in ASP.NET

Any one please tell me how to set the value of textbox.

function moreFieldsEditFunction(ExtraFname, ExtraFvalue) {
    document.getElementById('<%= TextBox1.ClientID %>').value =ExtraFvalue;
}

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

It is not working

I don't think that you are a million milles off to be honest, I have taken your code and put it into a web form with a button that can be clicked to call the function and it works, without seeing your mark up it will be difficult to diagnose but it should look something like this:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">

    <script type="text/javascript">

        function moreFieldsEditFunction(ExtraFname, ExtraFvalue) {
            document.getElementById('<%= TextBox1.ClientID %>').value = ExtraFvalue;
        }

    </script>
</head>
<body>
    <form id="form1" runat="server">

        <input type="button" onclick="moreFieldsEditFunction('TEST', 'TEST2')" value="Click Me" />    

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

    </form>
</body>
</html>

This should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM