473,500 Members | 1,955 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Assign values to button

29 New Member
hi, is it possible to assign values to button? I will not need to enter any values and when i click on the button, the values on the datagrid and database will automatically change. Is there anyway to do it? Thanx in advance.
Apr 4 '07 #1
8 1833
SammyB
807 Recognized Expert Contributor
hi, is it possible to assign values to button? I will not need to enter any values and when i click on the button, the values on the datagrid and database will automatically change. Is there anyway to do it? Thanx in advance.
You can use the Tag property of any control to store anything. You can add the Tag object at design or run time:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click
  2.     Dim b As Button = sender
  3.     MsgBox("Hi from " & b.Tag)
  4. End Sub
  5. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  6.     Button1.Tag = 19.98
  7.     Button2.Tag = 42
  8. End Sub
Note -- if you are writing in C#, you have to do casting. VB lets you be sloppy. HTH
Apr 4 '07 #2
fanoftvb
29 New Member
Thanx 4 the reply, I try it out and these errors occur

'Tag' is not a member of 'System.Web.UI.WebControls.Button'.
Name 'Button1' is not declared.

pls help...thanx
Apr 5 '07 #3
SammyB
807 Recognized Expert Contributor
Thanx 4 the reply, I try it out and these errors occur

'Tag' is not a member of 'System.Web.UI.WebControls.Button'.
Name 'Button1' is not declared.

pls help...thanx
Sorry, I was building a Window's App. To keep the Web controls lightweight, they do not have a Tag property, but it is easy to add one by extending the WebControls.Button class. Here is an example for a TreeNode. The code for an extended Button class would be identical.
Apr 5 '07 #4
fanoftvb
29 New Member
Hi, can u tell me how to do it, i don't quite understand caz i'm quite new to vb...
Apr 5 '07 #5
SammyB
807 Recognized Expert Contributor
Hi, can u tell me how to do it, i don't quite understand caz i'm quite new to vb...
I better let an ASP guru do that: I've never created a web form.
Apr 5 '07 #6
AricC
1,892 Recognized Expert Top Contributor
hi, is it possible to assign values to button? I will not need to enter any values and when i click on the button, the values on the datagrid and database will automatically change. Is there anyway to do it? Thanx in advance.
Why would you assign values to a button? Are you trying to change the text dynamically? What have you tried thus far?

Aric
Apr 7 '07 #7
fanoftvb
29 New Member
Why would you assign values to a button? Are you trying to change the text dynamically? What have you tried thus far?

Aric

Hi, i was thinking that if i click on the button the data in my database will change. I will not need to enter any information, the data will click automatically when i click on the button..is there a way to do it?
Apr 9 '07 #8
SammyB
807 Recognized Expert Contributor
Hi, i was thinking that if i click on the button the data in my database will change. I will not need to enter any information, the data will click automatically when i click on the button..is there a way to do it?
You coud do something simple like put the number in the button name, Btn1, Btn10, Btn42, etc.
Expand|Select|Wrap|Line Numbers
  1.     Private Sub Btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn1.Click, Btn10.Click, Btn42.Click
  2.         Dim b As Button = sender
  3.         Dim s As String = Strings.Right(b.Name, Len(b.Name) - 3)
  4.         Dim i As Integer = Integer.Parse(s)
  5.         MsgBox("Hi from " & i)
  6.     End Sub
Apr 9 '07 #9

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

Similar topics

2
15693
by: dskillingstad | last post by:
I'm trying to assign a custom value to a textbox. Here's what I have. I've created a module and "default value" code for a textbox which generates a custom auto-number (yyyy-0000) when a New...
26
7026
by: Brett | last post by:
I have created a structure with five fields. I then create an array of this type of structure and place the structure into an array element. Say index one. I want to assign a value to field3 of...
12
2313
by: Mark Kurten | last post by:
i have the code below: for starters the value of txtempid = 1 after i go through this routine (i put a break point on the txtname.value line), the value of txtEmpID is 2 (Just like it is...
4
2552
by: hb | last post by:
Hi, When I add an asp:button (ex: id=btnLog) on home.aspx, I need to create btnLog_Click() event in home.aspx.cs, and also link this event and the button in OnInit() method by adding:...
8
7379
by: Sergei | last post by:
Hi, I am displaying modal dialog and passing values from the main form to the modal dialog and back. It works fine but if I used the following syntax on Page_Load(just for testing) in VB to...
6
2246
by: david | last post by:
I try to use "for" loop to retrieve and assign values in web form. The code is in the following. But it can not be compiled. What I want to do is: txtQ1.Text =...
1
5757
by: ericthered | last post by:
I would like to build a loop to change button properties, not using a case select. Like this: Dim i As Integer Dim ButtonSizeW As Integer = 50 Dim ButtonSizeH As...
3
1577
by: Eugenio | last post by:
Hello everybody, I'm new to this forum, so sorry if i post something that has been already answered althought i couldn't find it in search. Anyway, there it goes: i have a search system which...
0
5238
by: hydro123 | last post by:
I am using VC++2008 and am trying to read data enetered in unbound datagridview to implement in function. Under button_click event I entered the following: // initialize varaibles from...
0
7136
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,...
0
7182
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
7232
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...
1
6906
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
7397
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...
1
4923
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...
0
4611
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...
0
1430
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 ...
0
316
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...

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.