468,253 Members | 1,296 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,253 developers. It's quick & easy.

button click

In asp.net I can put code for button click event. However I come to this
event twice. What is the reason and how to prevent or check second entry to
this event. I need to make sure that i do not run the same code twice.
Aleks Kleyn

Mar 26 '07 #1
4 1526
"Aleks Kleyn" <Al*********@MailAps.orgwrote in message
news:00**********************************@microsof t.com...
In asp.net I can put code for button click event. However I come to this
event twice. What is the reason and how to prevent or check second entry
to this event. I need to make sure that i do not run the same code twice.
Do you mean that you want to disable the button immediately after it has
been clicked, so that the user cann't click it a second time...?
Mar 26 '07 #2
what's causing you to come to the event twice?

Is the user clicking the button twice in a row?
or after post back is the user clicking the button again and you want to
prevent this?
or is the event triggering twice for one button click/

some more details please

I general ASP.NET practive you need to create mechanisms for persistance.
So, if you create a boolean to remember if the event is run,
you'll have to create a mechanism for this boolean value to be remember to
subsequent posts or amongst other pages.

Here are some methods you can use
1) Viewstate your variable
2) Session your variable
3) set an control on your pages value to remember your variable
4) Store this in a database
5) store this in a cookie

you can also look at disabling the button, or setting it to invisible

Good luck, HTH

"Aleks Kleyn" <Al*********@MailAps.orgwrote in message
news:00**********************************@microsof t.com...
In asp.net I can put code for button click event. However I come to this
event twice. What is the reason and how to prevent or check second entry
to this event. I need to make sure that i do not run the same code twice.
Aleks Kleyn

Mar 26 '07 #3
You could use this free OneClick control, which claims to meet your
requirements exactly:
http://www.metabuilders.com/tools/OneClick.aspx

--
I hope this helps,
Steve C. Orr,
MCSD, MVP, CSM, ASPInsider
http://SteveOrr.net
"Aleks Kleyn" <Al*********@MailAps.orgwrote in message
news:00**********************************@microsof t.com...
In asp.net I can put code for button click event. However I come to this
event twice. What is the reason and how to prevent or check second entry
to this event. I need to make sure that i do not run the same code twice.
Aleks Kleyn
Mar 27 '07 #4
No I do not want to disable the button. I observed this behavior some times
before, and now I see it again in win Vista, The code is simple.
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="New_ePrint.aspx.vb"
Inherits="New_ePrint" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >

<asp:Button ID="Button_AddSection" Runat="server" Text="<"
OnClick="Button_AddSection_Click" />

Partial Class New_ePrint
Inherits System.Web.UI.Page

Protected Sub Button_AddSection_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button_AddSection.Click
Dim intMaxId As Integer
FillSection()
End Sub
Now I put breakpoint on FillSection call and start web page. When I click
the button, I come to break point, execute FillSection, leave event.
Imediately after this I again on the break point to execute FillSection. But
I do not need this. If FillSection put data to database, I willl put wrong
data.

Aleks Kleyn

Mar 27 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Steve | last post: by
11 posts views Thread by CW | last post: by
3 posts views Thread by Imran Aziz | last post: by
6 posts views Thread by user | last post: by
7 posts views Thread by =?Utf-8?B?bWFydGluMQ==?= | last post: by
9 posts views Thread by Jonathan Wood | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.