473,888 Members | 1,588 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 1856
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.But ton'.
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.But ton'.
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.But ton 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
15742
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 Record button is clicked. The code checks the table for the highest value and then assigns 1 and inserts the value. I have a second text box which needs the same type of custom auto-number which has to be generated from a second command button. ...
26
7122
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 the structure inside the array. When I try this, an error about late assignment appears. Is it possible to assign a value to a structure field that is in an array? I'm currently getting around the problem by creating a new structure, assign...
12
2363
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 suppose to be) However, when i come into this function again, txtEmpID = 1 again For some reason the txtEmpID.value isn't retaining its actual value of 2 any ideas? Try
4
2574
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: this.btnLog.Click +=new System.EventHandler(this.btnLog_Click); Now, I need to generate some asp:button dynamically in an asp:table, and assign the event to all buttons. But in
8
7426
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 assign value form the object to text Box it gives error 'Object required' Dim strResponse As String strResponse = strResponse & "<script language=""JavaScript"">" & vbCrLf strResponse = strResponse & "var aForm; " & vbCrLf
6
2287
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 = ds.Tables("mmsSpecRecord").Rows(0)("Q1") txtQ2.Text = ds.Tables("mmsSpecRecord").Rows(0)("Q2") ..... txtQ10.Text = ds.Tables("mmsSpecRecord").Rows(0)("Q10") ------code ------- Dim field As String = "Q"
1
5791
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 Integer = 50 For i = 0 To 50 Dim z As Integer = i + 1 Dim x As New Button
3
1595
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 gives you the values you search for in a list box. The list box has its "Multi Select" property set to "Extended" which allows you to pick specific records from the list box. I also have a button to allow you to produce a report based on the values u've...
0
5308
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 dataGridView double C1; double INF1; double T1; //Read String values from each dataGridView Cell String^C1s = safe_cast<String^>(dataGridView1->Value); String^INF1s = safe_cast<String^>(dataGridView1->Value);
0
9961
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
9800
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
10777
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
10882
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
9597
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
7148
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();...
1
4642
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
2
4243
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3251
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.