Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP ASP.NET Visual-Studio .NET4 , +
How to display a msgbox in asp.net using C#?
I can't do it using windows.msgbox
It can be done by,
Response.Write("<script>alert('Item Already Exists')</script>");
But the problem I am facing is that, when the msgbox is being displayed, the actual webpage turns blank (i.e. full white), and on clicking OK, I am getting back the page again. Is there any way to display the msgbox as well as the page at the same time?
Posted 7-Sep-12 4:57am
Edited 7-Sep-12 5:06am
Nueman8.5K
v2
Comments
ryanb31 at 7-Sep-12 10:09am
   
This is because you are invoking it from C#. What you could do is use jQuery and use the document.ready() function so that it fires when the page has finished loading.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Well try with:
 
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + myStringVariable + "');", true);
 
Also check this article:
 
Simple MessageBox functionality in ASP.NET[^]
 
Cheers
  Permalink  
v2
Comments
Member 9413361 at 7-Sep-12 10:54am
   
msgbox("your message ") it also work
Mario Majčica at 7-Sep-12 11:12am
   
are you sure about that? In an ASP.NET project?!?!?
Aritra Nath at 7-Sep-12 16:33pm
   
i dont think msgbox works in asp.net
that was mentioned in my question
Aritra Nath at 7-Sep-12 16:36pm
   
@mario.. ur code works fine, i.e. i am getting the msgbox and the main page at the same time, but somehow while the msgbox is displayed, my masterpage menu alignment is getting mixed up. its coming back to normal after i click ok. any idea what is happning?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

You cant do Response.Write since it wipes out the content and put the response as what you are sending inside the Write method.
 
Instead lets say you have a button in your asp.net page and on click of the button you want to show the message box from C# then,You can do this on the button click event in C#
 
string javaScript = "alert('Item Already Exists');";
 

          Page.ClientScript.RegisterStartupScript(this.GetType(),"ButtonClickEventScript", javaScript,true);
  Permalink  
Comments
Aritra Nath at 7-Sep-12 16:38pm
   
ur code works fine, i.e. i am getting the msgbox and the main page at the same time, but somehow while the msgbox is displayed, my masterpage menu alignment is getting mixed up. its coming back to normal after i click ok. any idea what is happning?
Ashraff Ali Wahab at 7-Sep-12 17:27pm
   
This is because the script which aligns the menu gets executed after our alert script gets executed. That is always the problem with RegisterStartupScript since it doesn't guarantee order.
Aritra Nath at 8-Sep-12 1:02am
   
so any idea on how to fix this?? or is there any other way to display the msgbox so that the menu alignment stays intact??
Ashraff Ali Wahab at 8-Sep-12 16:55pm
   
Call the javascript function which aligns the menu before calling this alert statement.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

hello, use the following code.
 
protected void Page_Load(object sender, EventArgs e)
{
  string message = "Hello! Vinod.";
  
  ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", message);
}
 

Thanks!!!!
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

You have to add reference of using " system.windows.forms " to use messagebox.show feature.
It very simple.
for more questions mail me at " saurabhdhir3@gmail.com "
  Permalink  
v2
Comments
ThePhantomUpvoter at 6-Apr-13 7:55am
   
The messagebox would be displayed on the server computer not on the client side for the user to see. What would be the point of that?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web01 | 2.8.1411022.1 | Last Updated 6 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100