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

时间:2022-11-20 10:51:51

I am developing a website wherein I want ppl who visit the site to add their comments.

我正在开发一个网站,我希望访问该网站的人们添加他们的评论。

What I have done is, I have kept an add button and when the user clicks that button there will be a popup for adding comment. Now the user is not supposed to leave the field blank. So am doing the required validations in code behind and now I want to display an modal pop up error message when user tries to add comment without entering one of the field. How can I display the error message and then returning to back to the comments modal pop up..

我所做的是,我保留了一个添加按钮,当用户点击该按钮时,会有一个弹出窗口用于添加评论。现在用户不应该将该字段留空。所以在后面的代码中进行必要的验证,现在我想在用户尝试添加注释而不进入其中一个字段时显示模态弹出错误消息。如何显示错误消息然后返回到弹出的注释模式..

The code I have come up with is as below...

我提出的代码如下......

<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>

Please help me..

请帮帮我..

Thanks in advance

提前致谢

1 个解决方案

#1


1  

I found the solution for this problem:

我找到了解决这个问题的方法:

The modified code is as follows:

修改后的代码如下:

<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>

Source

资源

#1


1  

I found the solution for this problem:

我找到了解决这个问题的方法:

The modified code is as follows:

修改后的代码如下:

<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>

Source

资源