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

click event is fired twice on an enhanced Button Control

I created an enhanced Button Control in ASP NET 2.0 to add a delete
confirmation message and to disable the button if the user does not have
access.
The new button control has a "ConfirmMessage" property where you can set the
message you want displayed and a "SecurityKey" property to set the security
key for the button.
The securitykey works fine. The button is disabled if the user should not
have access to it.
The problem I have is with delete confirmation message. When the user
accepts the confirm message, the click event is fired twice.

If I look at the html source on the client, the button has 2 onclick
statements:
onclick="javascript:return confirm('Do you wish to delete this record ?');"
onclick="javascript:WebForm_DoPostBackWithOptions( new
WebForm_PostBackOptions(..."

I override the AddAttributesToRender with the attached code.

If I take out the writer.AddAttribute(HtmlTextWriterAttribute.Onclic k,
onClickScript) statement, then clicking on the button does nothing

Any help would be appreciated.

Protected Overloads Overrides Sub AddAttributesToRender(ByVal writer As
HtmlTextWriter)

writer.AddAttribute(HtmlTextWriterAttribute.Href, "#")

Dim onClickScript As String = "javascript:"
Dim actionScript As String = String.Empty

' Do not validate in design mode
If Not Me.DesignMode Then
If Not authorizedAccess(Me.SecurityKey.ToString, "E", "B")
Then
Me.Enabled = False
Else
If Me.ShowConfirm Then
actionScript = String.Concat("return confirm('",
EscapeJavaScript(ConfirmMessage), "');")
End If
End If
End If

If actionScript = String.Empty Then
actionScript =
Me.Page.ClientScript.GetPostBackEventReference(Me, "")
End If

If Me.Enabled AndAlso (Not (Me.Page Is Nothing)) Then
onClickScript += String.Concat(confirmScript, actionScript)
writer.AddAttribute(HtmlTextWriterAttribute.Onclic k,
onClickScript)
End If

If ShowStatusBarText Then
writer.AddAttribute("onmouseover",
String.Concat("javascript:window.status='", EscapeJavaScript(StatusBarText),
"';return true;"))
writer.AddAttribute("onmouseout",
"javascript:window.status='';return true;")
End If

MyBase.AddAttributesToRender(writer)

End Sub

Protected Overridable Function GetClientValidatedPostback(ByVal
control As Control, ByVal confirmScript As String) As String
Dim text1 As String =
control.Page.ClientScript.GetPostBackEventReferenc e(control, confirmScript)
Return ("{if (typeof(Page_ClientValidate) != 'function' ||
Page_ClientValidate()) " + confirmScript + text1 + "} ")
End Function
Nov 6 '07 #1
0 2305

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

Similar topics

3
by: Scott Schade | last post by:
I have a form onto which I add a control during execution. The control is a control that I wrote. The control has a number of controls on it. I would like to click on a button on the control and...
6
by: Michael Johnson Jr. | last post by:
I am trying to handle a button click event, which updates a web control table with data. The button is dynamically created in the table itself. When I call updateTable() in the Page_Load the new...
2
by: Oney | last post by:
I want to open a popup window when user click the web server button control When user click the button, only OnClik="OpenWindow(12)" is sent but no event happend no popup opened.After...
3
by: Imran Aziz | last post by:
Hello All, I have a search text and button that post data and my button handler filters the repeater control. However when the button is clicked the first time. The page_load event is being called...
41
by: JohnR | last post by:
In it's simplest form, assume that I have created a usercontrol, WSToolBarButton that contains a button. I would like to eventually create copies of WSToolBarButton dynamically at run time based...
5
by: kai | last post by:
Hi, In ASP.NET , what is the difference between OnClick and Click events for a button? Because we have button click event, it can trigger events, why we still need OnClick? Please help. ...
0
by: Demetri | last post by:
I have created a web control that can be rendered as either a linkbutton or a button. It is a ConfirmButton control that allows a developer to force a user to confirm if they intended to click it...
2
by: Chu | last post by:
Thanks everyone for taking a moment to read this. I've got a page where I use a LinkButton and I wire up a dynamic event to the button. When the user clicks the button, the event is fired as...
8
by: Learner | last post by:
Hello, I converted a VS 2003 project to VS 2005. It works perfectly alright in VS 2003 but when I try running in VS 2005 I got strange thing going on. The code (my button click event ) runs...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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.