When I click a button I don't want the click event to fire. Is this
possible?
In fact, what I would really like is to be able to intercept the click
event, perform some action, and then prevent the click from passing through
to the button.
Any help or suggestions much appreciated.
Charles 24 7698
Why don't you just remove or condition the code from the Click event?
The button will do nothing by itself.
--
Klaus H. Probst, MVP http://www.vbbox.com/
"Charles Law" <bl***@nowhere. com> wrote in message
news:eU******** ******@TK2MSFTN GP11.phx.gbl... When I click a button I don't want the click event to fire. Is this possible?
In fact, what I would really like is to be able to intercept the click event, perform some action, and then prevent the click from passing
through to the button.
Any help or suggestions much appreciated.
Charles
Hi Klaus
I actually have a lot of buttons, and text boxes, and dropdowns, and so on
that I want to do this for. To condition the code in every single one would
be tedious and repetitive.
I am really looking for the principle so that I can apply it to other types
of control as well. For example, I also want to prevent a dropdown from
dropping down, and prevent the button from appearing depressed when it is
clicked. In a nutshell, I want the control to behave like it never got the
click / mouse down event.
Charles
"Klaus H. Probst" <us*******@vbbo x.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. .. Why don't you just remove or condition the code from the Click event?
The button will do nothing by itself.
-- Klaus H. Probst, MVP http://www.vbbox.com/ "Charles Law" <bl***@nowhere. com> wrote in message news:eU******** ******@TK2MSFTN GP11.phx.gbl... When I click a button I don't want the click event to fire. Is this possible?
In fact, what I would really like is to be able to intercept the click event, perform some action, and then prevent the click from passing through to the button.
Any help or suggestions much appreciated.
Charles
Well that's possible, you can simply inherit from the control itself and
make it do anything you want.
For example, you could put some code in the OnClick method and so your stuff
there and prevent things from bubbling up to the container.
But that assumes that you started there - it's going to be hard to retrofit
to your existing code, especially if you have a lot of it.
--
Klaus H. Probst, MVP http://www.vbbox.com/
"Charles Law" <bl***@nowhere. com> wrote in message
news:e#******** *****@tk2msftng p13.phx.gbl... Hi Klaus
I actually have a lot of buttons, and text boxes, and dropdowns, and so on that I want to do this for. To condition the code in every single one
would be tedious and repetitive.
I am really looking for the principle so that I can apply it to other
types of control as well. For example, I also want to prevent a dropdown from dropping down, and prevent the button from appearing depressed when it is clicked. In a nutshell, I want the control to behave like it never got the click / mouse down event.
Charles
"Klaus H. Probst" <us*******@vbbo x.com> wrote in message news:%2******** ********@TK2MSF TNGP09.phx.gbl. .. Why don't you just remove or condition the code from the Click event?
The button will do nothing by itself.
-- Klaus H. Probst, MVP http://www.vbbox.com/ "Charles Law" <bl***@nowhere. com> wrote in message news:eU******** ******@TK2MSFTN GP11.phx.gbl... When I click a button I don't want the click event to fire. Is this possible?
In fact, what I would really like is to be able to intercept the click event, perform some action, and then prevent the click from passing through to the button.
Any help or suggestions much appreciated.
Charles
Hi Charles,
Seems like you want to create your own Control-Classes.
Do something like:
Namespace Law
Public Class myButton
Inherits System.Windows. Forms.Button
' Add your code
Namespace Law
Public Class myComboBox
Inherits System.Windows. Forms.ComboBox
' Add your code
Of course you have to fill in the details yourself, use attirbutes, etc.....
HTH,
Michael
"Charles Law" <bl***@nowhere. com> wrote in message
news:eU******** ******@TK2MSFTN GP11.phx.gbl... When I click a button I don't want the click event to fire. Is this possible?
No. If there's an event handler, the event will fire.
In fact, what I would really like is to be able to intercept the click event, perform some action, and then prevent the click from passing
through to the button.
The click can "pass through" to the button all day long and nothing will
happen other than it will appear pressed and then unpressed. That's all the
button will do on its own. If you don't want YOUR CODE executed when a Click
event occurs, write more code to detect this condition and then simply DON'T
EXECUTE your code.
* "Charles Law" <bl***@nowhere. com> scripsit: When I click a button I don't want the click event to fire. Is this possible?
In fact, what I would really like is to be able to intercept the click event, perform some action, and then prevent the click from passing through to the button.
\\\
Imports System
Imports System.Windows. Forms
Public Class UserControl1
Inherits Button
Private m_Clickable As Boolean
Public Property Clickable() As Boolean
Get
Return m_Clickable
End Get
Set(ByVal Value As Boolean)
m_Clickable = Value
End Set
End Property
Protected Overrides Sub OnClick(ByVal e As EventArgs)
If Me.Clickable Then
MyBase.OnClick( e)
End If
End Sub
End Class
///
Then you can use this button instead of the standard Windows Forms
button. One possible extension would be to provide a 'BeforeClick'
event that passes in a 'BeforeClickEve ntArgs' object that provides a
'Cancel' property. If the event is handled and 'Cancel' is set to
'True', the 'Click' event would not be raised.
The code above will extend the standard button with a 'Clickable'
property. If this property is set to 'False', the 'Click' event won't
fire.
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Thanks again Klaus.
Along with the other responses, I think everyone is pointing in the same
direction: basically, I have to create my own control and inherit from
button, etc. As you suggest, though, I'm not starting from there, and retro
fitting is not really an option.
Ho hum.
Charles
"Klaus H. Probst" <us*******@vbbo x.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. .. Well that's possible, you can simply inherit from the control itself and make it do anything you want.
For example, you could put some code in the OnClick method and so your
stuff there and prevent things from bubbling up to the container.
But that assumes that you started there - it's going to be hard to
retrofit to your existing code, especially if you have a lot of it.
-- Klaus H. Probst, MVP http://www.vbbox.com/
"Charles Law" <bl***@nowhere. com> wrote in message news:e#******** *****@tk2msftng p13.phx.gbl... Hi Klaus
I actually have a lot of buttons, and text boxes, and dropdowns, and so
on that I want to do this for. To condition the code in every single one would be tedious and repetitive.
I am really looking for the principle so that I can apply it to other types of control as well. For example, I also want to prevent a dropdown from dropping down, and prevent the button from appearing depressed when it
is clicked. In a nutshell, I want the control to behave like it never got
the click / mouse down event.
Charles
"Klaus H. Probst" <us*******@vbbo x.com> wrote in message news:%2******** ********@TK2MSF TNGP09.phx.gbl. .. Why don't you just remove or condition the code from the Click event?
The button will do nothing by itself.
-- Klaus H. Probst, MVP http://www.vbbox.com/ "Charles Law" <bl***@nowhere. com> wrote in message news:eU******** ******@TK2MSFTN GP11.phx.gbl... > When I click a button I don't want the click event to fire. Is this > possible? > > In fact, what I would really like is to be able to intercept the
click > event, perform some action, and then prevent the click from passing through > to the button. > > Any help or suggestions much appreciated. > > Charles > >
Hi Michael
Seems like I *don't* really want to create my own class, but it seems that
it is my only option :-(
There has to be another way, doesn't there?
Charles
"Michael Maes" <mi*****@merlot .com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. .. Hi Charles,
Seems like you want to create your own Control-Classes.
Do something like:
Namespace Law Public Class myButton Inherits System.Windows. Forms.Button
' Add your code
Namespace Law Public Class myComboBox Inherits System.Windows. Forms.ComboBox
' Add your code Of course you have to fill in the details yourself, use attirbutes,
etc..... HTH,
Michael
Hi Jeff
As I mentioned, I have a lot of controls already, and retro-fitting
conditional code will be problematic. I even favour the inheritance route at
this stage, but I'm not happy.
But, I will persevere.
Charles
"Jeff Johnson [MVP: VB]" <i.***@enough.s pam> wrote in message
news:e8******** ******@TK2MSFTN GP09.phx.gbl... "Charles Law" <bl***@nowhere. com> wrote in message news:eU******** ******@TK2MSFTN GP11.phx.gbl...
When I click a button I don't want the click event to fire. Is this possible? No. If there's an event handler, the event will fire.
In fact, what I would really like is to be able to intercept the click event, perform some action, and then prevent the click from passing through to the button.
The click can "pass through" to the button all day long and nothing will happen other than it will appear pressed and then unpressed. That's all
the button will do on its own. If you don't want YOUR CODE executed when a
Click event occurs, write more code to detect this condition and then simply
DON'T EXECUTE your code.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Sally |
last post by:
I need to be able to click in a subform and run code but at the same time I
need to be able to scroll the records without running the code. I tried
coding the Enter event of the subform control but when I try to scroll the
records the code runs. The subform is continuous; all the controls are on
one line and the detail section is not exsposed above or below the controls.
I tried coding the detail Click event but nothing happened. I tried...
|
by: Stan |
last post by:
If a page has a button with event handler
private void btnAdd_Click(object sender, System.EventArgs e)
{
.......
}
this event handler fires every time I refresh the page in the browser with
F5 AFTER
the button was clicked.
|
by: Liqun Xu |
last post by:
Hallo NG,
I created a Button with Click-Event dynamically:
System.Web.UI.WebControls.Button bt_1 = new Button();
bt_1.Click += new EventHandler(bt_1_click);
and I implemented the Funktion bt_1_click in which I created a second
Button dynamically too.
System.Web.UI.WebControls.Button bt_2= new Button();
|
by: J McD |
last post by:
Hi
I have a DataGrid with an ImageButton column. When I click on an imagebutton I get a postback but it doesn't run the OnImgBtnClick method. I can actually comment out the line where I add this Click event to the ImageButton Column and it makes no difference, I still get a postback. This is driving me crazy...something seems to be causing an OnClick postback and it isn't my Click event
I've included the code below....any help will be...
|
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 such as when they do a delete.
Everything is great. By and large it will be used in my repeater controls
using the command event when the user clicks on it and so that event is
working great.
My issue is the Click event. When the control is...
| |
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
expected. In the event code for that button, a new LinkButton is added
to the page and is wired up to yet a different event, however when
clicked, the page is posted back but the event is not triggered.
I'm assuming it has something to do with the...
|
by: Rob Roberts |
last post by:
Is there any way to prevent a ButtonField in a GridView from doing a
postback when clicked? I want to use my own onclick handler to call
window.open('SomePage.aspx') to display a page in a new browser window when
the button is clicked.
I tried doing this in the RowCommand postback event by doing this in the
event handler:
Response.Write("<script>window.open('SomePage.aspx');</script>");
|
by: bill |
last post by:
I dynamically create buttons and associate them with an event using
AddHandler.
I want all the button events to fire at one time, when the page is posted,
instead of when each button is clicked.
How I stop the buttons from posting back when they are clicked?
Thanks
|
by: Diane Truyens |
last post by:
Hi,
I have a form with textboxes, a search button and a gridview. The textboxes
are filled with default values so that the gridview should return all rows
but not before the user has had the chance to change some of the textboxes
and has clicked the search button.
How can I avoid the gridview displaying all rows before the search button
was clicked?
Any Ideas? Thanks
Diane
|
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...
|
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,...
| |
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...
|
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,...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
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...
| |