473,396 Members | 1,789 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,396 software developers and data experts.

How to pop a message box in ASP.NET page

kai
Hi, All
I am trying to pop a message box in ASP.NET using JavaScript when I click
a button, but I realize the JavaScript works for HTML control button do not
work for ASP button.

Any idea how to use JavaScript to trigger a message box for ASP.NET button?

Thanks for any help.

Kai

Nov 18 '05 #1
7 4794
Hi kai,
Thank you for using Microsoft Newsgroup Service. Based on your description,
you want to popup a message box when a
ASP.NET server button is clicked. Is my understanding of your problem
correct?

If so, you may try use the ServerControl's "Attributes" collection property
to add the client side event binding. For example:

You've a ASP.NET button in page named "btnPop"

then in the page class, add such code:

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here

btnPop.Attributes.Add("onclick","alert(\"hello\")" );
}

Then when the server button is clicked, it'll first run the client side
script and then post back to the server side. You may have a try to check
out the above suggestion.

If you have any questions on it, please feel free to let me know.
Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Nov 18 '05 #2
Execute a line of code like this when you want a message box to be
displayed.
(This writes out the necessary client side javascript to your HTML page to
make the alert pop up as soon as the page is sent to their browser.)

RegisterStartupScript("startupScript", "<script
language=JavaScript>alert('This is my message.');</script>");

Here's more info:
http://msdn.microsoft.com/library/de...criptTopic.asp

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
Hire top-notch developers at http://www.able-consulting.com

"kai" <ka******@earthlink.net> wrote in message
news:vE*****************@newsread1.news.atl.earthl ink.net...
Hi, All
I am trying to pop a message box in ASP.NET using JavaScript when I click a button, but I realize the JavaScript works for HTML control button do not work for ASP button.

Any idea how to use JavaScript to trigger a message box for ASP.NET button?
Thanks for any help.

Kai

Nov 18 '05 #3
kai
Steve,
Thanks for your help. I will give a try.

Kai
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Execute a line of code like this when you want a message box to be
displayed.
(This writes out the necessary client side javascript to your HTML page to make the alert pop up as soon as the page is sent to their browser.)

RegisterStartupScript("startupScript", "<script
language=JavaScript>alert('This is my message.');</script>");

Here's more info:
http://msdn.microsoft.com/library/de...criptTopic.asp
--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
Hire top-notch developers at http://www.able-consulting.com

"kai" <ka******@earthlink.net> wrote in message
news:vE*****************@newsread1.news.atl.earthl ink.net...
Hi, All
I am trying to pop a message box in ASP.NET using JavaScript when I click
a button, but I realize the JavaScript works for HTML control button

do not
work for ASP button.

Any idea how to use JavaScript to trigger a message box for ASP.NET

button?

Thanks for any help.

Kai


Nov 18 '05 #4
kai
Hi, Steven
Thanks for your help. I will give a try.
Kai
"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:lQ**************@cpmsftngxa07.phx.gbl...
Hi kai,
Thank you for using Microsoft Newsgroup Service. Based on your description, you want to popup a message box when a
ASP.NET server button is clicked. Is my understanding of your problem
correct?

If so, you may try use the ServerControl's "Attributes" collection property to add the client side event binding. For example:

You've a ASP.NET button in page named "btnPop"

then in the page class, add such code:

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here

btnPop.Attributes.Add("onclick","alert(\"hello\")" );
}

Then when the server button is clicked, it'll first run the client side
script and then post back to the server side. You may have a try to check out the above suggestion.

If you have any questions on it, please feel free to let me know.
Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #5
kai

Hi, Steven

I implement your suggestion using VB.NET code:

Public Class WebForm1
Inherits System.Web.UI.Page
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
btnPop.Attributes.Add("onclick", "alert(\'hello\')")
End Sub
End Class
HTML code is:
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="WebForm1.aspx.vb" Inherits="WebApplication6.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<asp:Button id="btnPop" runat="server"></asp:Button>
</form>
</body>
</HTML>

I get error message:

"Run time error has occured. Do you whish to debug?
Line 10
Error: Invalid character"

What did I do wrong?

Thank you veru much for helping.
Kai
"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:lQ**************@cpmsftngxa07.phx.gbl...
Hi kai,
Thank you for using Microsoft Newsgroup Service. Based on your description, you want to popup a message box when a
ASP.NET server button is clicked. Is my understanding of your problem
correct?

If so, you may try use the ServerControl's "Attributes" collection property to add the client side event binding. For example:

You've a ASP.NET button in page named "btnPop"

then in the page class, add such code:

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here

btnPop.Attributes.Add("onclick","alert(\"hello\")" );
}

Then when the server button is clicked, it'll first run the client side
script and then post back to the server side. You may have a try to check out the above suggestion.

If you have any questions on it, please feel free to let me know.
Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #6
Either remove the escape characters - \ - from the single ticks.
btnPop.Attributes.Add("onclick", "alert('hello')")

Or write it as in the example you were given with regular quotes.
btnPop.Attributes.Add("onclick","alert(\"hello\")" );

Bob Lehmann

"kai" <ka******@earthlink.net> wrote in message
news:_S*****************@newsread1.news.atl.earthl ink.net...

Hi, Steven

I implement your suggestion using VB.NET code:

Public Class WebForm1
Inherits System.Web.UI.Page
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
btnPop.Attributes.Add("onclick", "alert(\'hello\')")
End Sub
End Class
HTML code is:
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="WebForm1.aspx.vb" Inherits="WebApplication6.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<asp:Button id="btnPop" runat="server"></asp:Button>
</form>
</body>
</HTML>

I get error message:

"Run time error has occured. Do you whish to debug?
Line 10
Error: Invalid character"

What did I do wrong?

Thank you veru much for helping.
Kai
"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:lQ**************@cpmsftngxa07.phx.gbl...
> Hi kai,
>
>
> Thank you for using Microsoft Newsgroup Service. Based on your

description,
> you want to popup a message box when a
> ASP.NET server button is clicked. Is my understanding of your problem
> correct?
>
> If so, you may try use the ServerControl's "Attributes" collection

property
> to add the client side event binding. For example:
>
> You've a ASP.NET button in page named "btnPop"
>
> then in the page class, add such code:
>
> private void Page_Load(object sender, System.EventArgs e)
> {
> // Put user code to initialize the page here
>
> btnPop.Attributes.Add("onclick","alert(\"hello\")" );
> }
>
> Then when the server button is clicked, it'll first run the client side > script and then post back to the server side. You may have a try to

check
> out the above suggestion.
>
> If you have any questions on it, please feel free to let me know.
>
>
> Steven Cheng
> Microsoft Online Support
>
> Get Secure! www.microsoft.com/security
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
>
>


Nov 18 '05 #7
kai
Hi, Bob
It works!!! Thanks
Kai
"Bob Lehmann" <none> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Either remove the escape characters - \ - from the single ticks.
btnPop.Attributes.Add("onclick", "alert('hello')")

Or write it as in the example you were given with regular quotes.
btnPop.Attributes.Add("onclick","alert(\"hello\")" );

Bob Lehmann

"kai" <ka******@earthlink.net> wrote in message
news:_S*****************@newsread1.news.atl.earthl ink.net...

Hi, Steven

I implement your suggestion using VB.NET code:

Public Class WebForm1
Inherits System.Web.UI.Page
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
btnPop.Attributes.Add("onclick", "alert(\'hello\')")
End Sub
End Class
HTML code is:
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="WebForm1.aspx.vb" Inherits="WebApplication6.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<asp:Button id="btnPop" runat="server"></asp:Button>
</form>
</body>
</HTML>

I get error message:

"Run time error has occured. Do you whish to debug?
Line 10
Error: Invalid character"

What did I do wrong?

Thank you veru much for helping.
Kai
"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:lQ**************@cpmsftngxa07.phx.gbl...
> Hi kai,
>
>
> Thank you for using Microsoft Newsgroup Service. Based on your

description,
> you want to popup a message box when a
> ASP.NET server button is clicked. Is my understanding of your problem > correct?
>
> If so, you may try use the ServerControl's "Attributes" collection

property
> to add the client side event binding. For example:
>
> You've a ASP.NET button in page named "btnPop"
>
> then in the page class, add such code:
>
> private void Page_Load(object sender, System.EventArgs e)
> {
> // Put user code to initialize the page here
>
> btnPop.Attributes.Add("onclick","alert(\"hello\")" );
> }
>
> Then when the server button is clicked, it'll first run the client side > script and then post back to the server side. You may have a try to check
> out the above suggestion.
>
> If you have any questions on it, please feel free to let me know.
>
>
> Steven Cheng
> Microsoft Online Support
>
> Get Secure! www.microsoft.com/security
> (This posting is provided "AS IS", with no warranties, and confers

no > rights.)
>
>



Nov 18 '05 #8

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

Similar topics

4
by: John | last post by:
Could anyone please help me on this?? I have a php script page, which is basically quiz. Visitors (after login in with their email address) are supposed to answer each question, and when they...
2
by: chints | last post by:
Hi, I have a very unique problem, i am submitting from a pdf form, when submitted goes to a asp page, which saves the data and redirects to a different page after saving the data. I am writing a...
3
by: Ed Burns | last post by:
Hi. I am trying to disable a user from going back to a previous page and displaying information previously shown. I want to give them the typical "Page has Expired" warning message. I am using Win...
2
by: J.B. | last post by:
Greetings all - I have been working on this issue for a while now and it has been frustrating to the point where I'm reaching out to the gurus of .NET for any suggestions. I have a webform...
2
by: Mike Moore | last post by:
asp.net app - How do you get Java-side code to communicate with server-side code? I have tried numerous ways and examples, but have been unsuccessful. Therefore, unless I get real lucky and find...
4
by: bnob | last post by:
In a Button clik event I have this code at the end of the event Response.Redirect("Page.aspx") But in this event I must show a message before redirect to the Page.aspx. I use to show Message...
2
by: Microsoft News | last post by:
What I have is a message box that pops up. It is another browser window. The code is a general function that you pass message, title and a key to. The box works great except, that if you are on a...
5
by: PontiMax | last post by:
Hi, when I press the OK button of my dialog box a long-running task is initiated. Therefore I would like to make visible a div section right after clicking the button where a user-friendly...
6
by: tshad | last post by:
I am trying to set up a Javascript popup box that has a way of sending back a message to asp.net on how to process some data. At the moment I am just doing: ...
1
by: tshad | last post by:
This is driving us crazy. And it only seems to happen in IE. Mozilla and Firefox don't have this problem. We get this message all the time, but I can't figure out why as it is not consistant...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.