473,414 Members | 1,738 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,414 software developers and data experts.

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 1832
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Steve | last post by:
Hi, Is it possible to make hitting the enter key in an ASP textbox run the code behind an ASP button on a form? I have a search page which users tend to type in the query then just hit enter...
11
by: CW | last post by:
I have message entry screen that's causing me a bit of an issue. At the moment, there are 2 buttons, one is used to send message to another user (btnSend) and another is used to send messages to...
1
by: Klaus Jensen | last post by:
Hi! This has been annoying me all day, and I can't get it to work It is really driving me nuts! Basicly this simple webapp created to illustrate my problem, renders five buttons, and adds a...
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...
5
by: Wonder | last post by:
How can I create or use the msgobx to show a message without a default button. The user has explicity to click on the button, so the msgbox closes it. Thanks,
21
by: Ben | last post by:
Hello I have frames set up in an asp.net application and need one frame to refresh another. Seeing as events need to be registered at the time the page is sent from the server, I was wondering...
6
by: user | last post by:
Hello, With ASP.NET2, how to program a button's click ? For example, I have two button and when i click the first one, i would like that the second one will be click too (by programming) ......
7
by: =?Utf-8?B?bWFydGluMQ==?= | last post by:
Hi, All, I create button in the code ( Dim Button as new Button), not using button web component (means not drap button and drop it ont he webform), after that I try to use button_click event,...
9
by: Jonathan Wood | last post by:
Does anyone know of any reason a button on a master page would have no effect? I have a complex HTML page that I'm converting to ASP.NET, and acknowledge I could have something odd that is...
1
by: daonho | last post by:
I tried to use javascript to trigger up the button click function when user press enter key from the textbox. This function work fine with a single button click such has login page. However, if the...
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?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
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
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...

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.