填写asp:label的输入

时间:2015-11-03 17:17:48

标签: javascript asp.net html5

一个值将被输入到asp:textbox中,然后当你点击提交时它将生成一个asp:标签,我需要的是获取生成的asp:标签并将其传递给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>

1 个答案:

答案 0 :(得分:2)

获取标签

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

将值分配给文本框

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

我根据您的要求制作了演示,这是工作演示

<强> 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>

Javscript

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);
        }