views:

146

answers:

4

how to display the 'successfully saved' message box in asp.net web application by using javascript.

any idea ???

A: 

Option 1

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.

Option 2

Another alternative is to use the JavaScript alert function, but it's pretty intrusive and old-fashioned looking.

T.J. Crowder
A: 
rahul
A: 

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); }

Ravia
ya i know this , but it is showing me the warning image with the message.
Ranjana
what warning are you getting
Ravia
A: 

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.

Kristof Claes