473,804 Members | 3,399 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

JavaScript In ASP Control

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

<asp:Button ID="cmdPPIPDele te" Text="Delete" Runat="server" CssClass="butto nDelete" CommandName="De lete" 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="javas cript"
function RecordDeleteCon firmation()

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

</script><asp:But ton ID="cmdPPIPDele te" Text="Delete" Runat="server" CssClass="butto nDelete" CommandName="De lete" OnClick='Javasc ript: RecordDeleteCon firmation()'></asp:Button

It gives me a compile error looking for ")"

What am I doing wrong

Nov 18 '05 #1
6 2264
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*******@disc ussions.microso ft.com> wrote in message
news:42******** *************** ***********@mic rosoft.com...
Hello, hopefully this is a simple question.. I have the following statement
<asp:Button ID="cmdPPIPDele te" Text="Delete" Runat="server" CssClass="butto nDelete" CommandName="De lete" 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="javas cript">
function RecordDeleteCon firmation()
{
confirm("Do you want to permanently delete this record")
}
</script><asp:But ton ID="cmdPPIPDele te" Text="Delete" Runat="server" CssClass="butto nDelete" CommandName="De lete" OnClick='Javasc ript:
RecordDeleteCon firmation()'></asp:Button>
It gives me a compile error looking for ")".

What am I doing wrong?

Nov 18 '05 #2
"Anatoli Trifonov" <sp**@avwork.co m> wrote in message
news:ep******** ********@TK2MSF TNGP09.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.A ttributes.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
johnwsaundersii i at hotmail
Nov 18 '05 #3
Thanks, If I am using a DataList, will I have to use the "OnItemCrea ted" 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 "OnItemCrea ted" 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_ItemDa taBound(Sender As Object, e As DataGridItemEve ntArgs)
If e.Item.ItemType <> ListItemType.He ader AND _
e.Item.ItemType <> ListItemType.Fo oter then
Dim deleteButton as LinkButton = e.Item.Cells(8) .Controls(0)
deleteButton.At tributes("oncli ck") = "javascript:ret urn " & _
"confirm('A re you sure you want to delete?');"
End If
End Sub

"Jim Heavey" <an*******@disc ussions.microso ft.com> schreef in bericht
news:10******** *************** ***********@mic rosoft.com...
Thanks, If I am using a DataList, will I have to use the "OnItemCrea ted"

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 "OnItemCrea ted" 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.ewe ka.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_ItemDa taBound(Sender As Object, e As DataGridItemEve ntArgs) If e.Item.ItemType <> ListItemType.He ader AND _
e.Item.ItemType <> ListItemType.Fo oter then
Dim deleteButton as LinkButton = e.Item.Cells(8) .Controls(0)
deleteButton.At tributes("oncli ck") = "javascript:ret urn " & _
"confirm('A re 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.It em Or ListItemType.Al ternatingItem Or
ListItemType.Ed itItem Or ListItemType.Se lectedItem. This will protect
against future item types being added to the ListItemType enumeration.
--
John Saunders
johnwsaundersii i 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******** *******@tk2msft ngp13.phx.gbl.. .
"Richard" <ri*****@nospam .com> wrote in message
news:40******** *************** @newsreader.ewe ka.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_ItemDa taBound(Sender As Object, e As

DataGridItemEve ntArgs)
If e.Item.ItemType <> ListItemType.He ader AND _
e.Item.ItemType <> ListItemType.Fo oter then
Dim deleteButton as LinkButton = e.Item.Cells(8) .Controls(0)
deleteButton.At tributes("oncli ck") = "javascript:ret urn " & _ "confirm('A re 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.It em Or ListItemType.Al ternatingItem Or
ListItemType.Ed itItem Or ListItemType.Se lectedItem. This will protect
against future item types being added to the ListItemType enumeration.
--
John Saunders
johnwsaundersii i at hotmail

Nov 18 '05 #7

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

Similar topics

2
2600
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 <script language="JavaScript" src="Scripts/filename.js"></script> When I register this control (drop control) on aspx page different than current folder in other words, when I have
1
5411
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 that), the popup window will have also a text box and a button. when the User click on the button the value on the textbox will be send back to the textbox on My_WUC. I hope I was clear off what I want to do. I've been searching for some ideas...
6
2532
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 get response from a Confirm() popup window to uncheck all server-side checkboxes placed in a panle of a web user control? I am using ASP.Net 2.0, Thanks. Need info...
2
2185
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 file(newsscroller.js) in my ASP page, everything works great in a normal HTML page, I can see the scroller just fine, but in an ASP page it just does not show, I get some error message that the control has not been initialize, so far I've been...
4
4245
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 control.. but if i add javascript in page in which i am adding user control then that javascript is executed properly. i tested by displaying alert message in javascript. can anyone tell
0
9705
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9576
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10323
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10074
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7613
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5515
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4291
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.