简体   繁体   English

无法在ASP.NET中使用JavaScript设置文本框值

[英]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: 老实说,我不认为您要离开百万富翁,我已经将您的代码放入了带有按钮的Web窗体中,可以单击该按钮以调用该函数,并且该函数有效,而不会看到您的标记即可很难诊断,但看起来应该像这样:

<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. 这应该工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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