473,385 Members | 2,269 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,385 software developers and data experts.

JavaScript In ASP Control

Hello, hopefully this is a simple question.. I have the following statemen

<asp:Button ID="cmdPPIPDelete" Text="Delete" Runat="server" CssClass="buttonDelete" CommandName="Delete" OnClick="return confirm('Please Confirm You Want To Delete Record')"></asp:Button

Each time I navigate to this page, I get a compile error of "CS1041 Identifier expected, return is a keyword"

Iif I take out the javascript, then I have no errors when I navigate to this page. So I am pretty confident that it is the Javascript causing the problem. I am wanting to bring up a dialoage box when the user presses the button to confirm the delete

I also tried the following

<script language="javascript"
function RecordDeleteConfirmation()

confirm("Do you want to permanently delete this record"

</script><asp:Button ID="cmdPPIPDelete" Text="Delete" Runat="server" CssClass="buttonDelete" CommandName="Delete" OnClick='javascript: RecordDeleteConfirmation()'></asp:Button

It gives me a compile error looking for ")"

What am I doing wrong

Nov 18 '05 #1
6 2250
Compiler tries to parse OnClick as server side script not client side.

What is the solution then? I do not know yet.
Some one else might be able to help.
Try adding scripts on the form level maybe ...

--
_____________________________________
Anatoli Trifonov
Software Developer & Consultant
Minds are like parachutes - they only function when open.
--Thomas Dewar
"Jim Heavey" <an*******@discussions.microsoft.com> wrote in message
news:42**********************************@microsof t.com...
Hello, hopefully this is a simple question.. I have the following statement
<asp:Button ID="cmdPPIPDelete" Text="Delete" Runat="server" CssClass="buttonDelete" CommandName="Delete" OnClick="return confirm('Please
Confirm You Want To Delete Record')"></asp:Button>
Each time I navigate to this page, I get a compile error of "CS1041 Identifier expected, return is a keyword".
Iif I take out the javascript, then I have no errors when I navigate to this page. So I am pretty confident that it is the Javascript causing the
problem. I am wanting to bring up a dialoage box when the user presses the
button to confirm the delete.
I also tried the following:

<script language="javascript">
function RecordDeleteConfirmation()
{
confirm("Do you want to permanently delete this record")
}
</script><asp:Button ID="cmdPPIPDelete" Text="Delete" Runat="server" CssClass="buttonDelete" CommandName="Delete" OnClick='javascript:
RecordDeleteConfirmation()'></asp:Button>
It gives me a compile error looking for ")".

What am I doing wrong?

Nov 18 '05 #2
"Anatoli Trifonov" <sp**@avwork.com> wrote in message
news:ep****************@TK2MSFTNGP09.phx.gbl...
Compiler tries to parse OnClick as server side script not client side.

What is the solution then? I do not know yet.
Some one else might be able to help.
Try adding scripts on the form level maybe ...


In the codebehind, you can add:

cmdPPIPDelete.Attributes.Add("onclick", "return confirm('Please Confirm You
Want To Delete Record')")

You don't want to use the "javascript:" prefix except in the href of an <a>
tag.
--
John Saunders
johnwsaundersiii at hotmail
Nov 18 '05 #3
Thanks, If I am using a DataList, will I have to use the "OnItemCreated" event to associate the script to the control? The example you provided assumed that it was an "ordinary" control. Am I correct in needing to use the "OnItemCreated" event to find the control and then load the value into the control?
Nov 18 '05 #4
here ya go for a on ItemDataBound.
Look at the IF statement, it make sure it doesnt put an onclick event to the
header and footer and i suggest you keep it in or else you will get an error
:D

Sub DataGrid_ItemDataBound(Sender As Object, e As DataGridItemEventArgs)
If e.Item.ItemType <> ListItemType.Header AND _
e.Item.ItemType <> ListItemType.Footer then
Dim deleteButton as LinkButton = e.Item.Cells(8).Controls(0)
deleteButton.Attributes("onclick") = "javascript:return " & _
"confirm('Are you sure you want to delete?');"
End If
End Sub

"Jim Heavey" <an*******@discussions.microsoft.com> schreef in bericht
news:10**********************************@microsof t.com...
Thanks, If I am using a DataList, will I have to use the "OnItemCreated"

event to associate the script to the control? The example you provided
assumed that it was an "ordinary" control. Am I correct in needing to use
the "OnItemCreated" event to find the control and then load the value into
the control?
Nov 18 '05 #5
"Richard" <ri*****@nospam.com> wrote in message
news:40***********************@newsreader.eweka.nl ...
here ya go for a on ItemDataBound.
Look at the IF statement, it make sure it doesnt put an onclick event to the header and footer and i suggest you keep it in or else you will get an error :D

Sub DataGrid_ItemDataBound(Sender As Object, e As DataGridItemEventArgs) If e.Item.ItemType <> ListItemType.Header AND _
e.Item.ItemType <> ListItemType.Footer then
Dim deleteButton as LinkButton = e.Item.Cells(8).Controls(0)
deleteButton.Attributes("onclick") = "javascript:return " & _
"confirm('Are you sure you want to delete?');"
End If
End Sub


Richard, I'd suggest that Jim use e.Item.Cells(8).FindControl instead of
assuming that it will always be Control 0. Also, I think I'd have tested for
ItemType = ListItemType.Item Or ListItemType.AlternatingItem Or
ListItemType.EditItem Or ListItemType.SelectedItem. This will protect
against future item types being added to the ListItemType enumeration.
--
John Saunders
johnwsaundersiii at hotmail
Nov 18 '05 #6
yup, its a much better answer, i just copied the code from an old db project
of mine as an answer to his second question.

"John Saunders" <jo**************@notcoldmail.com> schreef in bericht
news:%2***************@tk2msftngp13.phx.gbl...
"Richard" <ri*****@nospam.com> wrote in message
news:40***********************@newsreader.eweka.nl ...
here ya go for a on ItemDataBound.
Look at the IF statement, it make sure it doesnt put an onclick event to the
header and footer and i suggest you keep it in or else you will get an

error
:D

Sub DataGrid_ItemDataBound(Sender As Object, e As

DataGridItemEventArgs)
If e.Item.ItemType <> ListItemType.Header AND _
e.Item.ItemType <> ListItemType.Footer then
Dim deleteButton as LinkButton = e.Item.Cells(8).Controls(0)
deleteButton.Attributes("onclick") = "javascript:return " & _ "confirm('Are you sure you want to delete?');"
End If
End Sub


Richard, I'd suggest that Jim use e.Item.Cells(8).FindControl instead of
assuming that it will always be Control 0. Also, I think I'd have tested

for ItemType = ListItemType.Item Or ListItemType.AlternatingItem Or
ListItemType.EditItem Or ListItemType.SelectedItem. This will protect
against future item types being added to the ListItemType enumeration.
--
John Saunders
johnwsaundersiii at hotmail

Nov 18 '05 #7

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

Similar topics

2
by: New User | last post by:
I have a System.Web.UI.UserControl as custom control and I have a javascript block for user control. The problem is I want to bring src attribute from outside as property or other method. e.g...
1
by: Jorge Ponte | last post by:
hi I have a Web User Control (ascx) - lets call it "My_WUC" - in a Web form. In that WUC I want have a textbox and a button. I want to click on the button and open a popup (I use javascript for...
6
by: den 2005 | last post by:
Hi everybody, Question 1: How do you set the values from server-side to a client-side control or how do you execute a javascript function without a button click event? Question 2: How do you...
2
by: verci | last post by:
Hi guys, sorry if this seems stupid but I'm a newbie, I'm running Windows XP Pro SP2, IE 7, VS2005, ASP.net 2.0 The problem is that I'm trying to display this news scroller made in a Javascript...
4
by: archana | last post by:
Hi all, i am having one user control. what i want is to add javascript which will gets called on button click of user control. but user control is not working if i add javascript in user...
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
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
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
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.