【问题标题】:fill a input from asp:label [closed]填充来自asp的输入:标签[关闭]
【发布时间】:2016-02-03 23:15:51
【问题描述】:

一个值将被输入到 asp:textbox,然后当你点击提交时它会生成一个 asp:label,我需要的是获取生成的 asp:label 并将其传递给 HTML 输入字段。我想要 HTML 或 JavaScript 格式的。

<asp:TextBox CharacterCasing="Upper" ID="usrpart" runat="server" Width="75px"  style='text-transform:uppercase' CausesValidation="True"></asp:TextBox><!--entered text and click submit-->

<asp:Label id="usrpart0" runat="server"></asp:label><br /><!--displays what was typed in the textbox and submitted to the server-->

<input id="asptext" type="hidden" value=""> <!--this is where i need asp:label's value passed--><!--this value is used to generate a QR code>

【问题讨论】:

  • 所有发布的都是程序描述。但是,我们需要您ask a question。我们无法确定您想从我们这里得到什么。请edit您的帖子包含一个我们可以回答的有效问题。提醒:请确保您知道what is on-topic here,请我们为您编写程序,建议是题外话。

标签: javascript asp.net html


【解决方案1】:

获取标签

var name = document.getElementById("<%=txtUserName.ClientID %>").value;

将值分配给文本框

 document.getElementById("asptext").value = name ;

我根据您的要求做了一个demo,这里是工作演示

HTML

   <form id="form1" runat="server">
        <div>
            <asp:Button ID="Button1" OnClientClick="javascript:return CallService();" runat="server" Text="Submit" />

            <asp:TextBox CharacterCasing="Upper" ID="usrpart" runat="server" Width="75px"  style='text-transform:uppercase' CausesValidation="True"></asp:TextBox><!--entered text and click submit-->

<asp:Label id="usrpart0" runat="server"></asp:Label><br />

<input id="asptext" type="hidden" value=""/> 
        </div>
    </form>

JavaScript

function CallService() {
            var usrpart0 = document.getElementById("<%=usrpart.ClientID %>").value;
            document.getElementById("<%=usrpart0.ClientID %>").innerHTML = usrpart0;
            document.getElementById("asptext").value = document.getElementById("<%=usrpart0.ClientID %>").innerHTML;
            alert(document.getElementById("asptext").value);
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-29
    • 1970-01-01
    • 2015-01-26
    • 1970-01-01
    相关资源
    最近更新 更多