messagebox in asp.net? how?

G

Guest

Hi everyone!

Never before have I had so many problems displaying a message to the user
(being a programmer for the last 4 years)!

What I would like to do is show a message e.g. when a procedure fails, etc.

Tried searching google, tried with divs, managed to 'implant' a div in my
master page to show info and error messages,
but I have two problems with it:
1) dropdown's display on top of this div!
2) can't produce confirm div (stop the javascript code and wait for user
interaction)

So, what would you suggest - recommend me?

Thanks in advance!
 
S

Scott M.

Since your ASP.NET code runs on the server and it is the client that is
responsible for messageboxes/confirms/alerts, you can't use server-side code
to do this directly.

The simplest thing to do is just to put an ASP:Label control on the page in
the position you *would* want the message to go, but leave its text property
blank Then, when your server-side code needs to send the client a message
simply fill in the text property of the label. Remember to set the label's
EnableViewState property to false so you don't see old messages.

Or, you could use server-side code to produce client-side javascript, which
could make your messagebox for you:

If someTest Then
response.write("<SCRIPT LANGUAGE='JavaScript'>alert('You have done
something bad! ')</SCRIPT>")
End If

-Scott
 
G

Guest

sorry about that, but I forgot to mention that I need to display server side
messages...

I already use and know about alert and confirm in javascript
 
G

Guest

thanks! I'll try them both!

One last thing though:
can I use absolute positioning to show the label on the center of the user's
screen?
 
S

Scott M.

See my second suggestion in my other reply.


patrickdrd said:
sorry about that, but I forgot to mention that I need to display server
side
messages...

I already use and know about alert and confirm in javascript
 
M

Mark Rae

sorry about that, but I forgot to mention that I need to display server
side
messages...

Take a step back here...

How can you display anything on a server...?

Even if you did manage to display a message server-side, who would ever see
it...? Your users certainly wouldn't...:)
 
S

Scott M.

Sure, you would need to use your own client-side JavaScript to determine the
center of the screen though and set the label's position prior to populating
it. You can also use a label's visible property to show/hide it as
necessary.
 
S

Scott M.

So will the following:

FONT
FACE
SIZE
COLOR
BLOCKQUOTE
BGCOLOR

etc., etc, etc.

If you are using HTML or XHTML Transitional (as millions do), this will not
pose any problem.
 
B

Boyd Ferris

sorry about that, but I forgot to mention that I need to display server side
messages...

I already use and know about alert and confirm in javascript

A JavaScript solution to a modal dialog box is two create two DIVs.
One DIV will have absolute positioning, transparent and placed over
the entire screen, which will capture all mouse and keyboard. The
other DIV will contain your HTML to produce your dialog box. When you
want to show the dialog box, turn on the DIV to capture mouse input
for the entire screen, and then turn on the other DIV to show the
dialog box, positioning it in a convenient location. Use CSS z-index
to ensure that the dialog box is on top of the transparent DIV.
 
G

Guest

yes, ok,
but I've tried with response.write (asp.net 2005),
when an insert procedure returns an error show a custom error message to the
client and didn't work!
no error message, nothing!

does anyone know why?
 
M

Mark Rae

yes, ok,
but I've tried with response.write (asp.net 2005),
when an insert procedure returns an error show a custom error message to
the
client and didn't work!
no error message, nothing!

does anyone know why?


<asp:Button ID="cmdSave" runat="server" Text="Save" OnClick="cmdSave_Click"
/>


protected void cmdSave_Click(object sender, EventArgs e)
{
// try to save the record...

if (<.....save didn't work...>)
{
ClientScript.RegisterStartupScript(GetType(), "failed",
"alert('Record was not saved');", true);
return;
}
}
 
S

Scott M.

....And you point is? There's the W3C and then there is the real world,
happiness is somewhere in between. Using the language attribute on a script
tag is the least of your worries if you want to be HTML or XHTML strict
compliant. VS. NET still generates heaps and heaps of deprecated tags. But
that is perfectly ok because HTML or XHTML Transitional ARE standards.
 
P

Przemek Ptasznik

Scott M. napisa³(a):
...And you point is? There's the W3C and then there is the real world,
happiness is somewhere in between.
this is poor excuse to not being able to generate clear, standard
compliant documents.
VS. NET still generates heaps and heaps of deprecated tags.
When you let vs.net do that it will be. But it's not reason to generate
tag soup and serve it to your users hoping they uses IE.
My asp.net apps (both 1.1 and 2.0) are valid xhtmls with tableless
layouts and fully separated content(xhtml), layout(css) and
behavior(js). And it was not big deal to achieve this. And they work in
most borwsers (that have js support. however it's achievable to make it
work without js too, but it involves much more work).
It's a fact that vs.net enables people with very low knowledge and
skills in web technologies to build "websites", but those "websites"
will be mostly very low quality and will work as author wants in IE only
and will have very messy html code - tag soup. Typical asp.net developer
has no background knowledge about web technologies basics (how http
works (get and post methods), how browsers renders documents, how
javascript works, even how asp.net works). Just look into many posts on
this newsgroup - they shows exactly what i said.
I know that asp.net allows me to work on higher level of abstraction,
and it's great. I can produce websites faster and with less coding. But
it all doesn't make me free to build poor coded websites and tell
everybody that's not my fault - asp.net does it.
Using asp.net is most effective when you know exactly what lies beneath,
and understand it's mechanisms that generates (x)html code. In this case
you can build standard compliant sites and don't have to make stupid
excuses about "milions of people that doing it that way".
It's like : Lets eat shit! Millions of flies can't be wrong!

Mark has noticed, that you show an example that uses deprecated
attribute and it was good. This is the right way to teach people how
they should build websites. IMHO there was no need to try to defend your
code.
But
that is perfectly ok because HTML or XHTML Transitional ARE standards.
Transitional specifications are standards, but it's not the same as "tag
soup" that is using strange tags combinations to achieve visual effects.
It's not about sets of allowed tags and attributes, it's rather about
how you use this tags and attributes and what for.
 
N

Nitin Sharma

Hii

you can use Try Catch blocks here for solving error's or we can say to
stop breaking application
This will give u a small Pop-up Alert box with the error message... in
asp.net....

try
{
your code goes here
}
catch (Exception ex)
{
Response.Write("<script
language='javascript'>window.alert(" + '"' + ex.Message + '"' +
");</script>");

}

some time idea's come in our mind also as a pop-up...... :)
So here u go ........

Nitin Sharma NXS
 
N

Nitin Sharma

Hii

you can use Try Catch blocks here for solving error's or we can say to
stop breaking application
This will give u a small Pop-up Alert box with the error message... in
asp.net....

try
{
your code goes here
}
catch (Exception ex)
{
Response.Write("<script
language='javascript'>window.alert(" + '"' + ex.Message + '"' +
");</script>");

}

some time idea's come in our mind also as a pop-up...... :)
So here u go ........

Nitin Sharma NXS
 
S

Scott M.

Inline...


Mark Rae said:
That we shouldn't be advising people to use deprecated syntax...

That's your opinion and I happen to think it's wrong. HTML or XHTML have
Transitional "flavors" that are, in fact, W3C standards. There is
absolutley nothing wrong with using them.

??? Like what...???

The FONT tag with the FACE, SIZE, COLOR attributes just for starters, but
since it uses these all over the place, they are a perfect example. Many of
the other deprecated tags/and attributes are used widely by VS.NET, MS
FrontPage and non-MS editors. Oh and yes, the the LANGUAGE attribute for
the SCRIPT tag is produced when you tell VS .NET to insert a server script
block into your HTML (and it doesn't even put the TYPE="text/javascript" in
there either).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top