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

Alert/Message

Hi all

How do I present questions/messages to the user while I am in a CLICK event
of a button ?

I was told to look for javascript/vbscript but could not make it work.

Please advise
Guy
Oct 4 '06 #1
8 1881
Guy,

Javascript functions alert and confirm is the way to go. You put them in the
client-side onclick event handlers. Example:

In the <headsection of your aspx page:
<script>
function askUser(text)
{
return confirm(text);
}
</script>

In the < bodysection:
<ASP:Button id=myButton runat=server onclick="return askUser('Please
confirm...')" ...

In this simple case you could write just
<ASP:Button id=myButton runat=server onclick="return confirm('Please
confirm...')" ...
without having a separate script in the <headsection. I just wanted to
demonstrate you the general way of doing this sort of things.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"Guy Cohen" <no*****@please.comwrote in message
news:OU**************@TK2MSFTNGP03.phx.gbl...
Hi all

How do I present questions/messages to the user while I am in a CLICK
event of a button ?

I was told to look for javascript/vbscript but could not make it work.

Please advise
Guy

Oct 4 '06 #2
Hi Eliyahu

I am familiar with that type of code
BUT :)
What if I need to show the alert or ask the question while being in
btnThis_Click (and use vb code...)

I was told to use : RegisterStartupScript

I need a sample pleaseeeeeeeeeeeee
TIA
Guy Cohen
"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:uo**************@TK2MSFTNGP05.phx.gbl...
Guy,

Javascript functions alert and confirm is the way to go. You put them in
the client-side onclick event handlers. Example:

In the <headsection of your aspx page:
<script>
function askUser(text)
{
return confirm(text);
}
</script>

In the < bodysection:
<ASP:Button id=myButton runat=server onclick="return askUser('Please
confirm...')" ...

In this simple case you could write just
<ASP:Button id=myButton runat=server onclick="return confirm('Please
confirm...')" ...
without having a separate script in the <headsection. I just wanted to
demonstrate you the general way of doing this sort of things.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"Guy Cohen" <no*****@please.comwrote in message
news:OU**************@TK2MSFTNGP03.phx.gbl...
>Hi all

How do I present questions/messages to the user while I am in a CLICK
event of a button ?

I was told to look for javascript/vbscript but could not make it work.

Please advise
Guy


Oct 4 '06 #3
If you want the alert prior to doing work, the best method, per MSDN, is to
use the Emit Client Script method(s) and add the "attribute" for OnClick to
call the script. If if can be after the click event is finished, you can
Emit the code in the event handler. On the later, if the person refreshes
the page, the popup will come up again, but refresh will also refire the
event handler, so it is a proper action.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com

*************************************************
Think outside of the box!
*************************************************
"Guy Cohen" <no*****@please.comwrote in message
news:OU**************@TK2MSFTNGP03.phx.gbl...
Hi all

How do I present questions/messages to the user while I am in a CLICK
event of a button ?

I was told to look for javascript/vbscript but could not make it work.

Please advise
Guy

Oct 4 '06 #4
"Guy Cohen" <no*****@please.comwrote in message
news:Oi**************@TK2MSFTNGP03.phx.gbl...
I am familiar with that type of code
BUT :)
What if I need to show the alert or ask the question while being in
btnThis_Click (and use vb code...)

I was told to use : RegisterStartupScript
That's incorrect.
I need a sample pleaseeeeeeeeeeeee
In your Page_Load, add the following:

btnThis.Attributes.Add("onclick", "return confirm('Are you sure you want to
do this?');")
Oct 4 '06 #5
My example will work for btnThis_Click. If the user confirms the action, you
will get the server-side event as usual. If he cancels, there won't be any
server-side event either. This is what "return " for.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"Guy Cohen" <no*****@please.comwrote in message
news:Oi**************@TK2MSFTNGP03.phx.gbl...
Hi Eliyahu

I am familiar with that type of code
BUT :)
What if I need to show the alert or ask the question while being in
btnThis_Click (and use vb code...)

I was told to use : RegisterStartupScript

I need a sample pleaseeeeeeeeeeeee
TIA
Guy Cohen
"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:uo**************@TK2MSFTNGP05.phx.gbl...
>Guy,

Javascript functions alert and confirm is the way to go. You put them in
the client-side onclick event handlers. Example:

In the <headsection of your aspx page:
<script>
function askUser(text)
{
return confirm(text);
}
</script>

In the < bodysection:
<ASP:Button id=myButton runat=server onclick="return askUser('Please
confirm...')" ...

In this simple case you could write just
<ASP:Button id=myButton runat=server onclick="return confirm('Please
confirm...')" ...
without having a separate script in the <headsection. I just wanted to
demonstrate you the general way of doing this sort of things.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"Guy Cohen" <no*****@please.comwrote in message
news:OU**************@TK2MSFTNGP03.phx.gbl...
>>Hi all

How do I present questions/messages to the user while I am in a CLICK
event of a button ?

I was told to look for javascript/vbscript but could not make it work.

Please advise
Guy



Oct 4 '06 #6
"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:ee**************@TK2MSFTNGP02.phx.gbl...
My example will work for btnThis_Click. If the user confirms the action,
you will get the server-side event as usual. If he cancels, there won't be
any server-side event either. This is what "return " for.
Your example was:

<ASP:Button id=myButton runat=server onclick="return confirm('Please
confirm...')" ...

That's going to try to run a server-side onclick event, is it not...?
Oct 4 '06 #7
Oops... you are right, I forgot that the server-side event has the same
name. Sure one should use Attributes.

Thank you

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:u8**************@TK2MSFTNGP05.phx.gbl...
"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:ee**************@TK2MSFTNGP02.phx.gbl...
>My example will work for btnThis_Click. If the user confirms the action,
you will get the server-side event as usual. If he cancels, there won't
be any server-side event either. This is what "return " for.

Your example was:

<ASP:Button id=myButton runat=server onclick="return confirm('Please
confirm...')" ...

That's going to try to run a server-side onclick event, is it not...?

Oct 4 '06 #8
dgk
On Wed, 4 Oct 2006 16:09:03 +0200, "Eliyahu Goldin"
<RE**************************@mMvVpPsS.orgwrote:
>Oops... you are right, I forgot that the server-side event has the same
name. Sure one should use Attributes.

Thank you
Or, use OnClientClick:

<asp:Button ID="btnDelete" runat="server" Text="Delete"
OnClientClick="return confirm('Confirm deletion?')" />

The problem with this approach (which I do use) is that it isn't
really easy to notice in the code. It's only visible in the Source
view in Visual Studio, not Design view or code behind. I don't
normally look too much in the Source view but since I know this is
there, I guess it's ok.
Oct 5 '06 #9

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

Similar topics

2
by: Robert Nurse | last post by:
Hi All, I've got a strange problem in IE that I wonder if anyone has seen before. Basically, I've got a two window scenario. The parent window opens the child via window.open(). The child...
3
by: dgmoore | last post by:
Hello - I'm having trouble with JavaScript alerts in an imagemap. The mapped areas are cells in a table, and the alerts display info related to the cell that is clicked. The problem is that,...
11
by: Alistair Saldanha | last post by:
I'm looking for the event that is fired by Internet Explorer to an "alert": <SCRIPT> Alert("You already have a session open") </SCRIPT> The event would be webBrowser.Document.???? Much...
6
by: bonehead | last post by:
Greetings, I'm working on an e-mail form (btw many thanks to Philip Ronan for the very cool email address format tester function, best I've seen so far). I've been trying, with limited...
4
by: PH | last post by:
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...
3
by: Ersin Gençtürk | last post by:
hi, I wrote a function like this : public static void Alert(string message){ message=message.Replace("'","\'"); message=message.Replace("\n","\\n"); ...
22
by: Tony Girgenti | last post by:
Hello. I'm developing and testing a web application using VS.NET 2003, VB, .NET Framework 1.1.4322, ASP.NET 1.1.4322 and IIS5.1 on a WIN XP Pro, SP2 computer. I'm using a web form. Using...
3
by: Wayne Deleersnyder | last post by:
Hi All, I'm trying to create a function that will cause a pop-up alert to appear if dates which were chosen from a drop-down list were invalid on a page. There's 4 dates, so there's the...
24
by: Jeremy J Starcher | last post by:
While reading c.l.j, I've noticed that some people prefer and indeed even recommend the use of "window.alert()" over "alert()". I can't find any technical reason to make this distinction, and...
20
by: Peter | last post by:
I need a popup alert after a post back. 1) user clicks on the submit button 2) Server side code runs and if the result is false I want to display a java script alert("It did not work") How to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.