Hani Honey
Hani Honey

Reputation: 2131

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

Upvotes: 2

Views: 22343

Answers (3)

Richard Ev
Richard Ev

Reputation: 54117

For a simple approach, you can have a script block that contains 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.

Upvotes: 4

Valeklosse
Valeklosse

Reputation: 1017

I have used Ajax to accomplish this myself.

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.

However below is a snippet of the asp.net code

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

Although this is a complex way in some respect but has many uses.

Upvotes: 3

musefan
musefan

Reputation: 48415

You can do this with simple javascript like this...

alert("my error message");

Here is more info on using javascript

Upvotes: 1

Related Questions