[英]Asp.Net popup error message
Is there a way I can display an error message in a popup box? 有没有办法在弹出框中显示错误信息? I'm using Asp.Net (C#), and on our webpage, if an order goes throug incorrectly we display an error message.
我正在使用Asp.Net(C#),在我们的网页上,如果订单不正确,我们会显示错误消息。 Now, we would like to be able to do so using some sort of pop-up method (maybe Ajax?) - it should be able to take a string value to display the error message.
现在,我们希望能够使用某种弹出方法(也许是Ajax?)来实现这一点 - 它应该能够采用字符串值来显示错误消息。
For a simple approach, you can have a script block that contains alert("your error message")
. 对于一个简单的方法,您可以拥有一个包含
alert("your error message")
的脚本块alert("your error message")
。 If you want the popup to be styled as the rest of your website then you could render your error message into a div
element and use a jQuery dialog to display it as a modal dialog within your page. 如果您希望将弹出窗口设置为网站的其余部分,则可以将错误消息呈现为
div
元素,并使用jQuery对话框将其显示为页面中的模式对话框。
I have used Ajax to accomplish this myself. 我自己用Ajax来完成这个。
Using the ModalPopupExtender and setting the PopupControlID to an Asp Panel, I usually put this into a User Control so it can be easily used through a website. 使用ModalPopupExtender并将PopupControlID设置为Asp Panel,我通常将其放入用户控件中,以便通过网站轻松使用。
However below is a snippet of the asp.net code 但是下面是asp.net代码的片段
<div class="modalPopupAlign">
<asp:LinkButton ID="lnkConfirm" Style="display: none;" CausesValidation="false" runat="server" PostBackUrl="#">Confirm</asp:LinkButton>
<ajax:ModalPopupExtender ID="lnkConfirm_ModalPopupExtender" runat="server" TargetControlID="lnkConfirm" PopupControlID="pnlConfirmation" BackgroundCssClass="modalBackground" DropShadow="true" RepositionMode="None">
</ajax:ModalPopupExtender>
<div id="pnlConfirmation" class="modalPopup" style="display: none;">
<br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div class="modalPopupContainerAlign">
<div>
<asp:Image ID="imgIcon" CssClass="modalPopupImage" runat="server" />
<asp:Label ID="lblMessage" CssClass="modalPopupMessage" runat="server"></asp:Label>
<div class="modalPopupTextbox"><asp:TextBox ID="txtValue" Width="200px" MaxLength="100" Visible="false" runat="server"></asp:TextBox></div>
<asp:Button ID="btnAction" runat="server" CausesValidation="false" CssClass="defaultButton" Text="OK" />
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
It does take some time to get it working properly as I have had a few errors with the script manager, which I currently have setup in a master page. 它确实需要一些时间才能正常工作,因为我在脚本管理器中遇到了一些错误,我目前在母版页中设置了这些错误。
Just might give you a direction to head for, and the CSS can help shape and colour the message box. 只是可能会给你一个方向,而CSS可以帮助塑造和着色消息框。
Although this is a complex way in some respect but has many uses. 虽然这在某些方面是一种复杂的方式,但有许多用途。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.