3

我在 <div> 标记中有 Asp.net 文本框,单击“btnReply”后,<div> 由 Jquery 对话框显示,因此用户在文本框中写下想法并单击“发送”按钮(jquery 对话框按钮)并回发发生.

但服务器端的 asp.net 文本框值为 null 。为什么 ?我的代码在这里:

     <div id="ReplyDiv"  style="display:none;">
             <asp:TextBox ID="txtReply" runat="server" Textmode="MultiLine"/>
     </div>

     <input type="button" id="btnReply" onclick="javascript:retuen ShowReplyDialog();"/>

      <asp:Button ID="AspBtnReply" runat="server" OnClick="AspBtnReply_Click" class="hidden"/>

     /*-----Jquery script----*/
    <script type="text/javascript">
      function ShowReplyDialog()
       {
         $("#ReplyDiv").dialog({
            width: 580,          
            buttons: {
               "Close": function () { $(this).dialog("close");} , 
               "Send" : function () {
                   //----Call Asp.net server method here
                   $("#<%=AspBtnReply.ClientID %>").click();
               }                    
            }
         }).parent().appendTo($("form:first"));
      }
    </script>
4

3 回答 3

5

经过大量搜索,我明白有一些原因:

  1. 我可以解决它 **Jquery UI Dialog 需要 z-index 样式 ** 。我的意思是 :

    <style>
     .ui-widget-overlay
     {
         z-index:0;
     }
    </style>
    

    并且需要 jquery :

      $("#..").dialog(.....).parent().parent().appendTo($("form:first"));
    
  2. 自从我使用 UpdatePanels 已经有一段时间了,但我相信在部分回发时,它们只会发送它们内部控件的更新值。因此,在 UpdatePanel 中移动 TextBox,或者使用 Javascript 在 UpdatePanel 中填充隐藏控件,并在更新时使用 TextBox 的上下文。

  3. 要在后面的代码中获取输入的值并通过服务器控件机制(textBox.Text)访问它们,它们的状态(和存在)需要保存在 ViewState 中。由于您使用 javascript 构建它们,因此它们的状态不会持久化,获取它们的值的唯一方法是使用 Request.Form 集合。

  4. 这个问题说最好的提示:jQuery Dialog-Postback but UpdatePanel doesn't get updated **

  5. 禁用控件是最好的问题: Retrieving the value of a asp:TextBox

于 2013-09-01T16:18:09.940 回答
3

Use hidden field value to store the textbox value

var Des = $("#txtDesc").val();
$("#hid").val(Des);

hid is the id of hidden field.

于 2013-08-30T10:47:01.693 回答
0

我刚刚遇到了同样的问题,经过两个小时的努力,我在我的引导模式中找到了表单标签。我已经删除了表单标签,并且值正在后端接收。

于 2022-02-02T20:26:20.990 回答