473,396 Members | 1,891 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.

What am i missing to raise a javascript alert

hello.
hopefully another quick newbie question for you....

I have a codebehind function coded to handle the click event of a
button. what this function does is insert values from a data grid
into the database. after that is done i want to send the user to
PageC, but before i do that i check a variable value. if that value
is "0" then i want to raise a javascript alert telling the user they
need to set some info in PageA and then automatically send them to
PageA

in the bottom of the function, i have the following....

If PrefCount = 0 Then
Dim strMessage As String = "Your data has not been set yet, you
will be sent to that page to fill it out"
Dim strScript As String = "<script language=JavaScript>alert('" &
strMessage & "');</script>"
If (Not Page.IsClientScriptBlockRegistered("prefCheckScrip t"))
Then
Page.RegisterClientScriptBlock("prefCheckScript", strScript)
End If
NextButton.Attributes.Add("onClick", "return prefCheckScript();")
Response.Redirect("PageA.aspx")
End If
as i step thru the code i see that everything is firing and working
correctly except that the javascipt pop-up doesn't come up and they
are sent directly to PageA, which is kind of what i want except i want
the popup alert to show and when they click OK, they are then
redirected to PageA.
i also tried using IsStartupScriptRegistered/RegisterStartupScript
first, same thing happens.

adding the onClick attribute to the button doesn't make much sense
here as they have already clicked the button to get into this
function. i put that in just because i saw it on web page out there.

basically trying to figure out how to kick off this javascript
conditionally. don't want it to popup/redirect if my IF condition is
false. but its not firing at all at this point.

thanks for any help!!

Jan 31 '06 #1
8 1931
Simon,

It is easier to set an extra label on your page that you use for this kind
of information and than use normal server side code. An error should be an
accident so an extra sent is than not that problem in my opinion. Try to
avoid JavaScript if it is not needed (which goes not forever).

Just my thought,

Cor
Jan 31 '06 #2
hi, thanks for the reply and advice. appreciate it.
even though this may not be the best use of executing javascript from
within a codebehind, it really was more of a functionality question.
in that there will surely be times when this processing is valid, so
i'm really just after what i need to do to execute javascript other
than an "onclick" type of event, something conditionally for example.

so besides these lines to register the javascript
If (Not Page.IsClientScriptBlockRegistered("prefCheckScrip t"))
Then
Page.RegisterClientScriptBlock("prefCheckScript", strScript)
End If

what do i use to execute the script?

thanks
Simon,

It is easier to set an extra label on your page that you use for this kind
of information and than use normal server side code. An error should be an
accident so an extra sent is than not that problem in my opinion. Try to
avoid JavaScript if it is not needed (which goes not forever).

Just my thought,

Cor


Jan 31 '06 #3
Simon,

Does this show it,

http://www.vb-tips.com/default.aspx?...c-d6e69a3128ec

I hope this helps,

Cor
Jan 31 '06 #4
hello, in that example, the script is put into a label and basically
run constantly (or immediately) on the page. what i was looking to do
is call the javascript function conditionally....

simple flow would be

IF true
execute javascript
else
do other vb code

thoughts?
Does this show it,

http://www.vb-tips.com/default.aspx?...c-d6e69a3128ec


Jan 31 '06 #5
Simon,

Your javascript is done at client side
Your vb code is done at serverside (in fact does it create client javascript
code).

Another sample I have is this one. It looks that bad that I don;t set it on
the site, probably does it however more what you are asking.

\\\
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim str As String
If Not IsPostBack Then
TextBox1.ForeColor = Color.White
TextBox1.BorderStyle = BorderStyle.None
Dim alertScript As String = _
"<script language=JavaScript>document.all.item('TextBox1'). value
" & _
" = prompt('Give me text','My name is nobody'); </script>"
RegisterStartupScript("Startup", alertScript)
Else
str = TextBox1.Text
End If
End Sub
///

And than there is of course AJAX.

http://www.vb-tips.com/default.aspx?...d-73214b27750c

However that is at the moment (one of) Ken's part of our website.

Cor
Jan 31 '06 #6
based on the server or client processing, there doesn't seem to be a
way to connect these elements. at least not that i'm seeing.
one thouhgt i had was that if the condition arrises, send them to a
page that pops up the alert like i want and then when they click OK on
the alert, send them to the page i wanted to. make sense? bad form?
Simon,

Your javascript is done at client side
Your vb code is done at serverside (in fact does it create client javascript
code).

Another sample I have is this one. It looks that bad that I don;t set it on
the site, probably does it however more what you are asking.

\\\
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim str As String
If Not IsPostBack Then
TextBox1.ForeColor = Color.White
TextBox1.BorderStyle = BorderStyle.None
Dim alertScript As String = _
"<script language=JavaScript>document.all.item('TextBox1'). value
" & _
" = prompt('Give me text','My name is nobody'); </script>"
RegisterStartupScript("Startup", alertScript)
Else
str = TextBox1.Text
End If
End Sub
///

And than there is of course AJAX.

http://www.vb-tips.com/default.aspx?...d-73214b27750c

However that is at the moment (one of) Ken's part of our website.

Cor


Jan 31 '06 #7
great site by the way, nice job. have that bookmarked now! thanks

http://www.vb-tips.com/default.aspx?...d-73214b27750c

However that is at the moment (one of) Ken's part of our website.


Jan 31 '06 #8
Simon,
based on the server or client processing, there doesn't seem to be a
way to connect these elements. at least not that i'm seeing.
one thouhgt i had was that if the condition arrises, send them to a
page that pops up the alert like i want and then when they click OK on
the alert, send them to the page i wanted to. make sense? bad form?
Simon,

Of course does that makes sense, however just as my first answer a label and
a whatever serverside button (button, linkbutton, imagebutton) can do all
you ask.

And the only thing is to make those controls at the right time visible on
the server side.

Cor

Your javascript is done at client side
Your vb code is done at serverside (in fact does it create client
javascript
code).

Another sample I have is this one. It looks that bad that I don;t set it
on
the site, probably does it however more what you are asking.

\\\
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim str As String
If Not IsPostBack Then
TextBox1.ForeColor = Color.White
TextBox1.BorderStyle = BorderStyle.None
Dim alertScript As String = _
"<script
language=JavaScript>document.all.item('TextBox1'). value
" & _
" = prompt('Give me text','My name is nobody'); </script>"
RegisterStartupScript("Startup", alertScript)
Else
str = TextBox1.Text
End If
End Sub
///

And than there is of course AJAX.

http://www.vb-tips.com/default.aspx?...d-73214b27750c

However that is at the moment (one of) Ken's part of our website.

Cor

Jan 31 '06 #9

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

Similar topics

13
by: Paul Gorodyansky | last post by:
Hi, Could not find the answer neither in FAQs not on the Web... On many javaScript 'tips' sites they say that do warn the user regarding missing .JS file one should do the following: <html>...
4
by: Wayne Wengert | last post by:
I jave a javascript function (see below) where if I uncomment the "if (isNaN(z)..." line, the function won't execute. I need to pass floating point numbers to the "map.center...." call and I had...
5
by: unwantedspam | last post by:
Hi All, What am I missing. I have trying to create a simple web based application. Basically there are three textboxes and two buttons (Save, Reset). I assume the code behind the save button...
3
tpgames
by: tpgames | last post by:
2x2 Sudoku doesn't work at all. The images don't show up on the grid. I don't understand JavaScript very well. Just learning it. Thanks! <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01...
9
by: Serguei.Goumeniouk | last post by:
Dear Experts, I have a very simple javascript codes with a following lines inside: ............................ var str = ""; .. . . . . . . . . . str = String(new Date()); // #1 str +=...
1
by: Binba | last post by:
I created the simplest embed QT movie page, and for starters, want to get the version. An HREF event works fine, but otherwise I get a fabulous "Unspecified error". I'm using MSIE6 WinXP SP2. ...
6
by: dmorand | last post by:
I'm having a little trouble with my ajax. I can see my results in IE, but not firefox. I'm assuming I'm missing some syntax somewhere. alert("Test " + results + testing); returns the values in...
2
by: lazukars | last post by:
I have been going over the this code for hours and am baffled. Am I missing something stupid? I am creating dynamic html via innerHTML for a webpage. There is an onClick function in this...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.