Help - Registered Javascript not executing

G

Guest

Hi,
On my Webform my ASP:Button does not execute the Javascript code which is
'added' to it on the page load, and I'm trying to figure out why. Please
take a look at my code and the error message and see if there's anything
obvious here:

'------ Here's where the javascript is registered and added to the ASP:Button:

Sub Page_Load()
Call setupClientScript()
If Not IsPostBack Then
btnUpdate.Attributes.Add("onclick", "return ConfirmUpdate();")
End if
End sub

Private Sub setupClientScript()
Dim js As String
js = "<script language=JavaScript> " & _
"Function ConfirmUpdate() " & _
"{ " & _
"return confirm('xxxx?'); " & _
"} " & _
"</script>"

'Register the script
If (Not IsClientScriptBlockRegistered("ConfirmUpdate")) Then
RegisterClientScriptBlock("ConfirmUpdate", js)
End If
End Sub

'------ Here's what I see when I view the source code when the page loads:
<form......
<script language=JavaScript> Function ConfirmUpdate() { return
confirm('xxxx?'); } </script>
.......
<TD vAlign="top" align="left">
<input type="submit" name="btnUpdate" value="Save Changes" onclick="return
ConfirmUpdate();if (typeof(Page_ClientValidate) == 'function')
Page_ClientValidate(); " language="javascript" id="btnUpdate" />

</TD>
......</form>

'------ And here's the error I see when I click on the little yellow
exclamation mark in the bottom left corner of the browser when I click on the
button:

Line: 20
Char: 11
Error: Expected ';'
Code: 0

So, I get this error and I do not get the pop-up confirmation window. Does
anybody recognize this error? Any help is appreciated.

Thanks,
John
 
B

Bruce Barker

javascript is case sensitive. "function" needs to be lowercase, and you
should use "window.confirm()" to be browser friendly.

-- bruce (sqlwork.com)
 
G

Guest

Bruce,
Thanks! Changing the case fixed the problem. But I ran into one more
issue; when I try to "Attribute.Add" this same function to a Datagrid
Checkbox, it puts it in the <span> section (which I see when I "view
source"), and it doesn't fire the function when the check box is changed.
Here's the html, do you see anything wrong here:

<span class="CssReportCell" OnCheckedChanged="SetChangeFlag();"><input
id="dgrdTRFP_dgrdReport__ctl2_chkDispatched" type="checkbox"
name="dgrdTRFP:dgrdReport:_ctl2:chkDispatched" checked="checked" /></span>

Thanks again!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top