473,804 Members | 2,139 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1882
"Aleks Kleyn" <Al*********@Ma ilAps.orgwrote in message
news:00******** *************** ***********@mic rosoft.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*********@Ma ilAps.orgwrote in message
news:00******** *************** ***********@mic rosoft.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*********@Ma ilAps.orgwrote in message
news:00******** *************** ***********@mic rosoft.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_e Print.aspx.vb"
Inherits="New_e Print" %>
<!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_AddS ection" Runat="server" Text="<"
OnClick="Button _AddSection_Cli ck" />

Partial Class New_ePrint
Inherits System.Web.UI.P age

Protected Sub Button_AddSecti on_Click(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Button_AddSecti on.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
6826
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 rather than actually clicking the search button, but this does not run the search code behind the button.
11
13967
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 all users (btnSendAll). When user hits enter, I also simulate the effect of clicking button (btnSend). However, what I found btnSend doesn't fire (unless I click on the button). The postback function I call is as follows: function...
1
1805
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 handler to the click event. When a button is clicked, the background-color is set to blue. Try running the page, and clicking the "Do stuff and update controls
3
8834
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 twice, once with postback true, and second time without postback. This only happens for this button. How can I sort out this issue, any clues what to look for to get this sorted please. <p>Search Bookmarks: <asp:TextBox ID="txtSearch"...
5
5433
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
8161
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 if I could place a hidden button in a frame that would have the attribute to refresh the other. I would need code to "invoke" the onclick event (ie i need code to click the button). is this possible? thanks.
6
2810
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) ... something like button2.click ??? Thanks for help ..
7
6871
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, it is not work, anyone can tell how to use button click event ? Thanks in advance, Martin
9
2749
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 affecting this. But I'm stuck. My handler is in C# code and the code looks right. But absolutely nothing happens when I click the button. protected void Button1_Click(object sender, EventArgs e)
1
7030
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 page has multiple button such login page with a search function somewhere around, then it's not respond properly. I have attached a brief example of two text boxes and two button. When ever a key is press on textbox one, I want to trigger...
0
9714
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
9594
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
10600
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10096
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...
0
6866
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5534
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
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3834
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.