从jquery对话框中获取多行文本框值

时间:2013-11-28 10:36:36

标签: c# javascript jquery asp.net

我尝试在我的asp网站上创建一个弹出对话框,其中包含发送消息的表单。 我在asp网络用户控制中做:

<asp:Panel runat="server" ID="panelMain" ToolTip="" style="display: none">
    <asp:Label runat="server" ID="Label1" AssociatedControlID="txtMessage" Text=""></asp:Label>:
    <br />
    <asp:TextBox runat="server" ID="txtMessage" ></asp:TextBox>
    <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator1" 
        ControlToValidate="txtMessage" Display="Dynamic" 
        ErrorMessage=""></asp:RequiredFieldValidator>
    <br />
    <asp:Button ID="butOk" runat="server" Text="" OnClick="butOk_Click"/>
    <asp:Button ID="butCancel" runat="server" Text="" CausesValidation="false" />
</asp:Panel>
<script type="text/javascript">
    $(document).ready(function()
    {
        $(".lbPopupLink").click(function() { //click hyperlink form main page
        $("#<%= this.panelMain.ClientID %>").css("display", "block");
        $("#<%= this.panelMain.ClientID %>").dialog
        ({
            autoOpen: false,
            modal: true,
            width: 400,
            height: 300,
            dialogClass: "popupDialog",
            resizable: false,
            overlay: { opacity: 0.5, background: "black" },
        }).dialog("open");

            return false;
        });

        $("#<%= this.butCancel.ClientID %>").click(function()
        {
            $("#<%= this.panelMain.ClientID %>").dialog("close");
            return false;
        });

        $("#<%= this.butOk.ClientID %>").click(function()
        {
            return $("#<%= this.panelMain.ClientID %>").dialogCloseAndSubmit($(this).attr("id"));
        });
    });
</script>

$.fn.extend({
    dialogCloseAndSubmit: function(butOkId)
    {
        var dlg = $(this).clone();
        $(this).dialog("destroy").remove();
        dlg.css("display", "none");
        $("form:first").append(dlg);
        $("#" + butOkId, dlg).click();
        return true;
    }
});

在代码背后:

protected void butOk_Click(object sender, EventArgs e)
    {
        // will be send mail
        Literal str_message = new Literal();
        str_message.Mode = LiteralMode.PassThrough;
        str_message.Text = "<br />Success!Message: " + this.txtMessage.Text;
        this.Page.Controls.Add(str_message);
    }

当TextBox是一行(Success!Message:hello)时,这一切都很好,但如果我将属性更改为TextMode =“MultiLine”,我没有TextBox值(成功!消息:)

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

也许试试:

$(this).find('textarea[id*=txtMessage]').val();

正如本answer

所述
相关问题