1

I am using MessageBox class in Asp.NET with C# by imposing the namespace

using System.Windows.Forms I have the following code:

/* Method for displaying the Message Box */
public void MsgBox()
{
    string message = "Do you want to modify the rate list?";
    string caption = "";
    MessageBoxButtons buttons = MessageBoxButtons.YesNoCancel;
    DialogResult result;
    result = MessageBox.Show(message, caption, buttons);
    if (result == DialogResult.Yes) {
        Response.Redirect("PaperRateList.aspx");
    }
}

/*Calling of the above method in the following event */
protected void Save_Click(object sender, EventArgs e)
{
    CompanyMaster_Insert();
    RateList_Save();
    MsgBox();  /*method*/  
}

Now the problem is that the message box is appearing behind the form in minimized mode.and the form can be closed before closing the message bos.I want this messagebox on the form and i want to close the form after closing the message box.

1
  • Using an winform messagebox might work while you are running your site in development mode, but not when you deploy it. The message box would appear in the hidden service session where neither server users nor the web user can see or access it. Don't mix winforms and ASP.NET like that. Commented Jan 4, 2012 at 7:55

3 Answers 3

3

MessageBox in web environment is not the best path to go, as it's a cheap way of implementing a windows form feature.

You have 2 ways to do this, server side (if you need to process some data) or client side (if you have all the data in the page and you can process it using javascript).

For you particulary example, you probably have a submit button like:

<asp:Button id="btnSave" runat="server" 
            onclick="btnSave_Click" text="Save Form" />

try to add this:

onclientclick="return confirm('Do you want to modify the rate list?');"

so it ends up like:

<asp:Button id="btnSave" runat="server" 
            onclick="btnSave_Click" text="Save Form"
            onclientclick="return confirm('Do you want to modify the rate list?');" />

That's just using a javascript method called confirm.

To make nice MessageBox examples, and to avoid the user not to mess up with the page while the message is visible, it's called Modal Dialog or Modal Window, try to search for it...

jQuery UI has a Modal element that you can use, and if you fancy AJax stuff and you're a beginner in ASP.NET, I strongly suggest you to try the ASP.NET Control Toolkit

Sign up to request clarification or add additional context in comments.

2 Comments

Thank You sir for your kind support if i want to redirect to another page by clicking the OK button then how will i be possible to do this?
why redirecting? when the user clicks OK the method on that page inside the OnClick event is fired and you can do everything there... if you really want to send the user to other page, either you don't understand the meaning of ASP.NET application/website and you still are confusing it with the old Classic ASP (witch then I would suggest you to see some ASP.NET WebForm Videos videos are in the right column) or you really know what you are doing and you can use Response.Transfer() in that method.
1

try

WebMsgBox class represents a message box for ASP.NET applications. This class has a static method Show, which is used to display a message box. The Show method takes a single argument of string type, which is the message you want to display.

private void Page_Load( object sender, System.EventArgs e )
{
  MessageBox.Show( "Hello World!" );
  MessageBox.Show( "This is my second message." );
  MessageBox.Show( "Alerts couldnt be simpler." );
}

Comments

0

You can use ModalPopupExtender of AJAXControlToolkit: ModalPopup Example

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.