带有文本输入的jQuery模态消息

时间:2015-02-10 17:00:27

标签: javascript c# jquery asp.net jquery-ui

我试图通过添加一个asp:Textbox来编辑jQuery模式消息框。 用户单击Button1后,出现对话框,提示用户输入QtyRun(double)。最后他们按Enter键。

如何将对话框中的用户输入传递给aspx表单上的变量或aspx控件(如标签)?

这是我的脚本和aspx代码:

<script> $(function() {
$('#Button1').click(function() {
    $("#dialog-message").dialog({
     modal: true,
     buttons: {
     Enter: function () {
        $('<%= Label1.Text %>').val($('<%= qtyRunText.Text %>').val());
                $(this).dialog("close");
        }}});
    })
});

<form id="form1" runat="server">
    <asp:Button ID="Button1" runat="server" Text="Button" />
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<div id="dialog-message" title="Roll# Found!" style="display:none">
<p>
Enter QtyRun: <asp:TextBox ID="qtyRunText" runat="server"></asp:TextBox>
</p>
</div>
</form>

1 个答案:

答案 0 :(得分:1)

第一个问题是为什么在服务器控件中需要这些值。

但是,你可以这样做:

您需要asp控件的ID:

Enter: function () {
        $('#<%=Label1.ID%>').val($('#<%=qtyRunText.ID%>').val());
                $(this).dialog("close");
        }}});

如果在服务器端设置这些ID属性,这将更友好:

Label1.ID = "asp_mylabel";
qtyRunText.ID = "asp_QtyRunText";

在javascript中,您可以拨打$('#asp_mylabel')$('#asp_QtyRunText')