473,326 Members | 2,255 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

javascript alert() after post back c#

PH
Does anyone know how to have the pop-up javascript alert,

Response.Write("<script language=javascript>alert('HEY!');</script>);

, pop-up after the page has been posted back? I am pressing a button,
validating data and then wanting to simply pop-up an alert if say the
login is empty. When I click the button though the page is blank but
the pop-up is there.
Nov 15 '05 #1
4 29886
In the postback function, you can use:

[C#]
string strScript = "<script language='JavaScript'>alert('Hey!')</script>";
Page.RegisterStartupScript("PopUp", strScript);

[VB.NET]
Dim strScript As String = "<script
language='JavaScript'>alert('Hey')</script>"
Page.RegisterStartupScript("PopUp", strScript)

However, it might be easier to use the RequiredFieldValidator control to
avoid an unecessary round-trip. If you want to have a popup, you could have
your custom javascript function validate the login field, and pop-up an
alert if it is empty, before submitting the form.

Regards,

Mun

"PH" <p_*******@yahoo.com> wrote in message
news:c5**************************@posting.google.c om...
Does anyone know how to have the pop-up javascript alert,

Response.Write("<script language=javascript>alert('HEY!');</script>);

, pop-up after the page has been posted back? I am pressing a button,
validating data and then wanting to simply pop-up an alert if say the
login is empty. When I click the button though the page is blank but
the pop-up is there.

Nov 15 '05 #2
Forms have a client-side event called "onSubmit". You can specify a
JavaScript function that will handle this event and perform client-side
validation before the form is posted back to the server.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"PH" <p_*******@yahoo.com> wrote in message
news:c5**************************@posting.google.c om...
Does anyone know how to have the pop-up javascript alert,

Response.Write("<script language=javascript>alert('HEY!');</script>);

, pop-up after the page has been posted back? I am pressing a button,
validating data and then wanting to simply pop-up an alert if say the
login is empty. When I click the button though the page is blank but
the pop-up is there.


Nov 15 '05 #3
Hi,

I think that the best way of doing this is using client side validation,
this avoid the round trip to the server just to report trivials errors as an
empty login.

Take a look at MSDN for how to use client side validators, it;s very easy.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"PH" <p_*******@yahoo.com> wrote in message
news:c5**************************@posting.google.c om...
Does anyone know how to have the pop-up javascript alert,

Response.Write("<script language=javascript>alert('HEY!');</script>);

, pop-up after the page has been posted back? I am pressing a button,
validating data and then wanting to simply pop-up an alert if say the
login is empty. When I click the button though the page is blank but
the pop-up is there.

Nov 15 '05 #4
For the simple validation you describe below, client side validators and
simple javascript may be sufficient. However, in our case, when we needed to
communicate back from the server to the client via a popup "alert", we wrote
a javascript function to call a standard html page that would become the
popup (so it could inherit the stylesheets and not just be a basic alert
box) and then on the main page, we placed a hidden text control.

The text control was unpopulated the first load. On submit, if no message
was needed, the textbox was still left empty. But if we needed to
communicate back, we populated the textbox with a message string from the
server that the onload() could see a) textbox isn't empty, so I need to
initiate the message popup and b) parse the hidden textbox to pull out the
values. The Javascsript function then opened the window, passing the
appropriate values it got from the textbox in the querystring to the message
page. Voila, customized, stylesheet driven alert boxes.

You can take it a step further and allow the popup to communicate back to
the parent then (for example, you might want an OK and CANCEL) so that the
main page can make some response to the user decision. We standardized
that HTML/Javascript function to give most of the standard responses of a
regular message box (OK only, OK/CANCEL, YES/NO, etc.)

It's a pain in the you know what to get it built and hooked up the first
time, but then it's the same thing over and over again when ever you need
it. Put the javascript in a #include and you won't have to be rewriting that
on each aspx/html page.

Todd

"PH" <p_*******@yahoo.com> wrote in message
news:c5**************************@posting.google.c om...
Does anyone know how to have the pop-up javascript alert,

Response.Write("<script language=javascript>alert('HEY!');</script>);

, pop-up after the page has been posted back? I am pressing a button,
validating data and then wanting to simply pop-up an alert if say the
login is empty. When I click the button though the page is blank but
the pop-up is there.

Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: TrvlOrm | last post by:
Can any one please help me...I am new to JavaScript and I have been struggling with this code for days now and can't figure it out. I would like to get the Buttons to correspond with the action...
14
by: tshad | last post by:
I posted this on the asp.net group, also. I wasn't sure whether this was an asp.net problem or a javascript problem. I have a page that was originally created from a program I found on the net...
15
by: binnyva | last post by:
Hello Everyone, I have just compleated a JavaScript tutorial and publishing the draft(or the beta version, as I like to call it) for review. This is not open to public yet. The Tutorial is...
9
by: tshad | last post by:
This is from my previous post, but a different issue. I have the following Javascript routine that opens a popup page, but doesn't seem to work if called from an asp.net button. It seems to work...
13
by: monomaniac21 | last post by:
hi i want to be able to trigger a javascript style popup alert in php (i want a message displayed on the actual page) is this possible?
7
by: julian.tklim | last post by:
Hi, I need to build an editable Datagrid with add & delete buttons on each row using javascript. DataGrid need not be pre-populated with values. To make the thing complicated, one of the...
6
by: den 2005 | last post by:
Hi everybody, Question 1: How do you set the values from server-side to a client-side control or how do you execute a javascript function without a button click event? Question 2: How do you...
4
by: =?Utf-8?B?R1ROMTcwNzc3?= | last post by:
Hi Guys, thanks for your help yesterday, I've got one more question, then I think I'm done for now,... Is it possible to insert recordset data in a javascript, for instance I have a javascript...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.