Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在asp.net中的模式弹出窗口中创建错误模式弹出窗口_C#_Asp.net_Ajax - Fatal编程技术网

C# 如何在asp.net中的模式弹出窗口中创建错误模式弹出窗口

C# 如何在asp.net中的模式弹出窗口中创建错误模式弹出窗口,c#,asp.net,ajax,C#,Asp.net,Ajax,我正在开发一个网站,我希望ppl谁访问该网站添加他们的意见 我所做的是,我保留了一个添加按钮,当用户单击该按钮时,将弹出一个添加评论的弹出窗口。现在,用户不应该将字段留空。因此,我在代码隐藏中执行所需的验证,现在我想在用户尝试添加注释而不输入任何字段时显示一条模式弹出错误消息。如何显示错误消息,然后返回到“注释”模式弹出窗口 我想出的代码如下 <asp:Button ID="addComment" runat="server" Text="Add Your Comment" OnClick

我正在开发一个网站,我希望ppl谁访问该网站添加他们的意见

我所做的是,我保留了一个添加按钮,当用户单击该按钮时,将弹出一个添加评论的弹出窗口。现在,用户不应该将字段留空。因此,我在代码隐藏中执行所需的验证,现在我想在用户尝试添加注释而不输入任何字段时显示一条模式弹出错误消息。如何显示错误消息,然后返回到“注释”模式弹出窗口

我想出的代码如下

<asp:Button ID="addComment" runat="server" Text="Add Your Comment" OnClick="addComment_Click" style="margin-top:10px;" Height="30px" ToolTip="Add Your comment about us" Font-Bold="True" />

<asp:scriptmanager id="ScriptManager1" runat="server"></asp:scriptmanager>
<ajaxtoolkit:modalpopupextender id="ModalPopupExtender1" runat="server" cancelcontrolid="btnCancel" targetcontrolid="addComment" popupcontrolid="Panel1" popupdraghandlecontrolid="PopupHeader" drag="false" backgroundcssclass="ModalPopupBG"></ajaxtoolkit:modalpopupextender>
<asp:panel id="Panel1" style="display: none" runat="server">
  <div class="HellowWorldPopup">
    <div class="PopupHeader" id="PopupHeader">
      <h3 style="color:white; font-family:'Palatino Linotype'">Add Your Comment</h3>
    </div>
    <div class="PopupBody">
      <p style="font-family:'Palatino Linotype'; margin-left:10px;">Your Name :</p>
      <p>
        <asp:TextBox ID="txtName" Text="" runat="server" Width="300px" style="margin-left:10px; font-family:'Palatino Linotype'; font-size:medium; font-style:italic"></asp:TextBox>
      </p>

      <p style="font-family:'Palatino Linotype'; margin-left:10px;">Your Comment:</p>
      <p>
        <asp:TextBox ID="txtComment" Text="" runat="server" Width="400px" style="margin-left:10px;font-family:'Palatino Linotype'; max-height:100px; font-size:medium; resize:none; font-style:italic" TextMode="MultiLine"></asp:TextBox>
      </p>

    </div>

    <asp:Button runat="server" id="btnOkay" Text="Done" OnClick="btnOkay_Click" style="font-family:'Palatino Linotype'; margin-bottom:10px; margin-left:10px;  width:100px; height:30px; font-size:small;font-weight:700" />
    <asp:Button ID="btnCancel" runat="server" Text="Cancel" style="font-family:'Palatino Linotype';width:100px; height:30px; margin-left:10px; font-size:small;font-weight:700" OnClick="btnCancel_Click" />

  </div>

</asp:panel>

添加您的评论
您的姓名:

您的评论:

请帮帮我


提前感谢

我找到了此问题的解决方案:

修改后的代码如下:

<asp:Button ID="addComment" runat="server" Text="Add Your Comment" OnClick="addComment_Click" style="margin-top:10px;" Height="30px" ToolTip="Add Your comment about us" Font-Bold="True" CausesValidation="false" />

<asp:scriptmanager id="ScriptManager1" runat="server"></asp:scriptmanager>
<ajaxtoolkit:modalpopupextender id="ModalPopupExtender1" runat="server" cancelcontrolid="btnCancel" targetcontrolid="addComment" popupcontrolid="Panel1" popupdraghandlecontrolid="PopupHeader" drag="false" backgroundcssclass="ModalPopupBG"
oncancelscript="ClearUI();" behaviorid="modalwithinput"></ajaxtoolkit:modalpopupextender>
<asp:panel id="Panel1" style="display: none" runat="server">
  <div class="HellowWorldPopup">
    <div class="PopupHeader" id="PopupHeader">
      <h3 style="color:white; font-family:'Palatino Linotype'">Add Your Comment</h3>
    </div>
    <div class="PopupBody">
      <p style="font-family:'Palatino Linotype'; margin-left:10px;">Your Name :</p>
      <p>
        <asp:TextBox ID="txtName" Text="" runat="server" Width="300px" style="margin-left:10px; font-family:'Palatino Linotype'; font-size:medium; font-style:italic"></asp:TextBox>
        <asp:requiredfieldvalidator id="RequiredFieldValidator1" runat="server" controltovalidate="txtName" errormessage="Please Enter your name" setfocusonerror="true" display="None"></asp:requiredfieldvalidator>
        <ajaxtoolkit:validatorcalloutextender id="RequiredFieldValidator1_ValidatorCalloutExtender" runat="server" targetcontrolid="RequiredFieldValidator1" behaviorid="textValidator" enabled="True">
        </ajaxtoolkit:validatorcalloutextender>
      </p>

      <p style="font-family:'Palatino Linotype'; margin-left:10px;">Your Comment:</p>
      <p>
        <asp:TextBox ID="txtComment" Text="" runat="server" Width="400px" style="margin-left:10px;font-family:'Palatino Linotype'; max-height:100px; font-size:medium; resize:none; font-style:italic" TextMode="MultiLine"></asp:TextBox>
        <asp:requiredfieldvalidator id="RequiredFieldValidator2" runat="server" controltovalidate="txtComment" errormessage="Please Enter the Comment" setfocusonerror="true" display="None">
        </asp:requiredfieldvalidator>
        <ajaxtoolkit:validatorcalloutextender id="Validatorcalloutextender1" runat="server" targetcontrolid="RequiredFieldValidator2" behaviorid="textValidator1" enabled="True">
        </ajaxtoolkit:validatorcalloutextender>
      </p>

    </div>

    <asp:Button runat="server" id="btnOkay" Text="Done" OnClick="btnOkay_Click" style="font-family:'Palatino Linotype'; margin-bottom:10px; margin-left:10px;  width:100px; height:30px; font-size:small;font-weight:700" />
    <asp:Button ID="btnCancel" runat="server" Text="Cancel" style="font-family:'Palatino Linotype';width:100px; height:30px; margin-left:10px; font-size:small;font-weight:700" OnClick="btnCancel_Click" />

  </div>

</asp:panel>

你能试试jQuery UI对话框而不是弹出式扩展器吗?@Deepu。。你是建议jqeury UI对话框只用于显示错误消息还是整个内容我认为更简单的方法是将上述代码移动到一个单独的aspx页面,该页面将在jQuery UI对话框中打开,然后你可以在其中打开验证弹出窗口。另外,您是否可以在客户端进行验证,以避免服务器回发。@Deepu我已经在iframe中加载了该页面,如果在该页面中加载单独的页面,则设计将更加复杂。不管怎样,我会试试的。你可以使用我以前发布的代码