473,799 Members | 3,148 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to include a button click procedure in an if then statement?

1 New Member
Im writing an if then statement and i want it to say something like this:

If intx = 1 and btn.click = true then
'the rest of code
end if

But obviously "btn.click" isnt a real command. Any ideas?
Oct 8 '11 #1
2 1767
!NoItAll
297 Contributor
To start I don't think you can do this. click is an asynchronous event and your If statement is synchronous. What I'm really saying here is that any goal of the above code is invalid so I would ask you to explain what it is you want to do.
If you wanted to know if a particular button had been clicked when this If statement runs, then that is easy. Simply create a global boolean flag such as

bMyButtonWasCli cked

In the button_click event set this value to TRUE and when your If Statement gets called it will be true only if the button event occurred. Be sure to set it to false inside your If code so it isn't just always true(unless thats what you want).

The other way is to reverse the logic and put your if statement inside the button_click event. If the IF statement runs then you know that the button_click event was called.

Expand|Select|Wrap|Line Numbers
  1. Private Sub button1_Click(sender As System.Object, e As System.EventArgs) Handles button1.Click
  2.     If intx = 1 then
  3.      'the rest of code
  4.     end if 
  5.  
  6. End Sub
  7.  
Oct 8 '11 #2
kadghar
1,295 Recognized Expert Top Contributor
Or you can use an STATE BUTTON and since the button is an object and its state is an attribute you can use it wherever you want.
Oct 11 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
3711
by: VbUser25 | last post by:
hi.. i have a form i accept some user inputs in the form. there is a link on the form from where i open the excel file in the same browser (not in a new page...simply using a href. i am also accepting input from the user in the excel. now i want to save the data in excel as well as on asp form. i can save directly thru vba code in excel to the db. but suppose the
2
9058
by: JCE | last post by:
I need to programmatically invoke an asp:Button click event from a javascript function. The page containing the script and the button is the HTML page associated with a WebUserControl-derived object (both the HTML and control are built in the same .ascx file) The target button simply fires an event in the WebUserControl-derived object. So, alternatively, if there was a mechanism to call a method (explicitly or using an event of some...
1
2631
by: Martin | last post by:
Hi, I have produced a custom server control that simple outputs a row of 26 buttons, one button for each letter of the english alphabet. now what I would like to do is catch the button click inside the server control when it is clicked on. however when I click on a button at present I get an error saying that the An error has occurred because a control with auto-generated id
20
57760
by: anthonymelillo | last post by:
Is there a way to call a button click event from somewhere else ? I have a text box where I would like to call a button click event when a user presses enter in the text box. Can I do this ? Thanks Tony
7
41837
by: code100579 | last post by:
Hi there, sorry if this is a really simple question. I need to write code for: If a button is pushed and then one variety of other buttons is pushed then certain options on the program will become "greyed out". Ie they can no longer be selected. I assume i need to create an event from the first button being pushed and then do if statements depending which button is pushed next
0
1370
by: PointyPointy | last post by:
Hey, I'm hoping some can help me out with a small problem I'm having. I've got two frames - Frame1 and Frame2. Both have aspx pages (Primarily VB) loaded in them but to keep this explination simple, I'll refer to them by their frame names. Frame1 has some text boxes. The user enters some values and clicks an asp button which then loads those values in session variables (Yea I know - bad me for using session variables). All that...
8
5929
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 twice? Has any one run into this kind of situation before please help. Am I missing some thing here? or do I need to set an option here? Thanks, -L
1
2046
by: Kuldeep | last post by:
Hello All, Visual Studio 2005 ASP.NET 2.0 C#.NET 2.0 I have an application which has a Button click event procedure as given below. protected void btn_Click(object sender, EventArgs e)
2
2113
by: Randy | last post by:
I have a form on which various controls are added dynamically depending on actions of the user. One of these actions allows the user to click a delete button that will remove various other controls. I was trying to accomplish this Click procedure by capturing the active contold using activecontrol.name and then removing it, but as soon as I click on the Delete button, the active controls changes to the delete button, not the control that...
2
5007
by: Max2006 | last post by:
Hi, I have a simple form with a button on it. After a button click postback, anytime user press F5 (browser page refresh), the button's OnClick event handler is called again without the button actually be pressed! Is this a bug in ASP.NET? Is there any technique to prevent that? I know that a Response.Redirect to the same page solves the issue, however because of some requirements; it is not an option for me.
0
9688
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
9544
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
10490
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
10259
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...
1
10238
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10030
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
9077
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5467
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
5589
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.