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("prefCheckScript"))
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!!
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
so besides these lines to register the javascript
If (Not Page.IsClientScriptBlockRegistered("prefCheckScript"))
Then
Page.RegisterClientScriptBlock("prefCheckScript", strScript)
End If
what do i use to execute the script?
thanks
Does this show it,
http://www.vb-tips.com/default.aspx?ID=972b8613-e881-400c-8ffc-d6e69a3128ec
I hope this helps,
Cor
simple flow would be
IF true
execute javascript
else
do other vb code
thoughts?
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?ID=12499601-19c8-43bf-94bd-73214b27750c
However that is at the moment (one of) Ken's part of our website.
Cor
> 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