how to display the 'successfully saved' message box in asp.net web application by using javascript.
any idea ???
how to display the 'successfully saved' message box in asp.net web application by using javascript.
any idea ???
You can put arbitrary content on the page at just about any location by simply creating and appending absolutely-positioned DOM elements, see this question's answer for details, but fundamentally:
var element;
element = document.createElement('div'); // Or whatever
element.style.position = "absolute";
element.style.left = "100px";
element.style.top = "100px";
element.style.width = "200px";
element.style.height = "200px";
document.body.appendChild(element);
The left
, top
, etc. can be any valid CSS values. You may also want to use z-index
to ensure it appears on top of other content.
Of course, when they click on it or something you'll want to remove it:
document.removeChild(element);
If you want to "grey-out" the underlying page and such, you can use an iframe shim to achieve that.
Another alternative is to use the JavaScript alert
function, but it's pretty intrusive and old-fashioned looking.
alert ( "Successfully saved" );
Display an alert dialog with the specified content and an OK button. See window.alert
The problem with an alert box is that it blocks the user from any further action. Better if you can show custom messages in containers like <span>
or <div>
and place them in the page.
Edit
If you can use jQuery then this one has diferent sets of custom alert boxes.
Response.write("<script>alert('Successfully saved !');</script>");
or call a javascript function which takes parameter Response.write("<script>ShowMessage('Successfully saved !');</script>");
//client side function
function ShowMessage(message) { alert(message); }
Instead of registering a some JavaScript code like this:
Response.write("<script>ShowMessage('Successfully saved !');</script>");
it is a bit cleaner to use this built-in method:
Page.ClientScript.RegisterStartupScript(this.GetType(), "showMyMessage", "ShowMessage('Successfully saved!');", true);
This is a bit cleaner than using Response.Write and it automatically prepends and appends your code with '<script type="text/javascript">' and '</script>'.
In your ShowMessage(MyMessage) function you could do a simple alert() or you could do something like T.J. Crowder suggests.