Logo 
Search:

Asp.net Forum

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds

Client side message (dialog) box

  Asked By: Arnold    Date: Sep 17    Category: Asp.net    Views: 2034
  

Has anybody been able to display a client-side message box
from the server-side?

In my project, when I try to add a contact to a database,
I check to see whether the contact already exists. If the contact
already exists, I want to indicate to the user that the contact
already exists and the contact was not added. If the contact
doesn't exists, I go ahead and add the contact to the database.

I've managed to write a javascript function to display a message
to confirm a delete using the onclick parameter after a button
is pressed, but that involves only client side code.

I am trying to use javascript and not vbscript.

Share: 

 

3 Answers Found

 
Answer #1    Answered By: Ryder Anderson     Answered On: Sep 17

The simplest thing to do is to use a label control and normally it will
not be visible. I also like to set the font color to red.



<asp:Label id=errMsg runat=server fore-color=red visible=false />

Then in the code, when I detect the error,

If(thatErrorThing)

{

errMsg.Text = "Some type of message";

errMsg.Visible = true;

return;

}

in the page load event, always do

errMsg.Text = "";

errMsg.Visible = false;

This will work very nicely and the user  will not have to deal with any
annoying alert window.

 
Answer #2    Answered By: Angelica Ramos     Answered On: Sep 17

But, if you WANT an alert window, you can just use a literal Web control
like so:


<asp:Literal id="ltlErrMsg" runat="server" />

And then set its Text property to the appropriate JavaScript code:

ltlErrMsg.Text = "<script language=""JavaScript"">" & vbCrLf &
"alert(""Hello, World!"");" & vbCrLf & "<" & "/script>"

 
Answer #3    Answered By: Lonnie Rogers     Answered On: Sep 17

Another option would be write  this


Page.RegisterStartupScript("alert_window", "<script
language=\"javascript\">alert('contact exists');</script>");

 
Didn't find what you were looking for? Find more on Client side message (dialog) box Or get search suggestion and latest updates.




Tagged: