2013-11-28 94 views
0

我嘗試在asp網站中用發送消息的窗體制作一個彈出對話框。 我做的asp網用戶控制:從jQuery對話框中獲取多行文本框的值

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

而這一切都很好,當文本框是一個行(成功消息:您好!),但如果我改變屬性TextMode =「MultiLine」我沒有TextBox值(成功!消息:)

我該如何解決這個問題?

回答

0

也許嘗試:

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

在本answer

討論