By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,190 Members | 765 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,190 IT Pros & Developers. It's quick & easy.

Back color property in button

P: 44
Hello Friends
I have created the project with 2 forms. In the first form, I have 2 buttons. The first button has the backcolor as "fusia" by default. If I click the button means then backcolor of the button should change into red color. Thats why I have given the coding as
Expand|Select|Wrap|Line Numbers
  1.  
  2. Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
  3.         If Button1.BackColor = Drawing.Color.Fuchsia Then
  4.             Button1.BackColor = Drawing.Color.Red
  5.         End If
  6.     End Sub
  7.  
The another button is the "Go" button which redirects to the next page.

In my next form I have the textbox with one button asking for the credit card number . If the valid credit card number is entered in the textbox & the button is clicked, then the back color of the button1 in the previous form should get changed into blue color.

I have created the sql table named "seat1". In that I have the following fields as sno,b1,b2. The table has the data as
sno b1 b2
--------------------------
1 fu fu
---------------------------

fu-------> fusia as back color
b1------->button1
b2------->button2

Just like that in the b1 field (with sno as 1) in the DB should change into "bl" which means "Blue as BackColor". For that, I have created the session variable in the previous form & used that variable. The coding is as follows

PREVIOUS FORM:
Expand|Select|Wrap|Line Numbers
  1.  Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
  2. Dim obj5 As Object
  3.         obj5 = Button1.BackColor
  4.         Session.Add("b1", obj5)
  5.     End Sub
  6.  
NEXT FORM:
Expand|Select|Wrap|Line Numbers
  1. Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
  2. Dim obj5 As Object
  3.         obj5 = CObj(Session("b1"))
  4.  End Sub
  5.  
Now the thing is If I click the "Button1" in the 2nd form then in the DB it should get updated as in the following manner

sno b1 b2
--------------------------
1 bl fu
---------------------------
and at the same time button1 in the previous form should have the back color as blue by default. For this I have given the coding as
Expand|Select|Wrap|Line Numbers
  1. Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
  2.  
  3. Dim obj5 As Object
  4.         obj5 = CObj(Session("b1"))
  5. Dim con As SqlConnection
  6.         Dim cmd As SqlCommand
  7.         Dim str As String
  8.         Dim rd As SqlDataReader
  9.         str = "user id=sa;password=;data source=AURO-RA4;initial catalog=suganya;server=AURO-RA4"
  10.         con = New SqlConnection(str)
  11.         Try
  12.             con.Open()
  13.         Catch
  14.         End Try
  15.         cmd = New SqlCommand
  16.         cmd.Connection = con
  17.         cmd.CommandText = "select count(credit) from credit where credit='" & Trim(TextBox3.Text.ToString()) & "'"
  18.         Dim cnt As Int16
  19.         cnt = cmd.ExecuteScalar()
  20.         If cnt <= 0 Then
  21.             Response.Write("Un authorise user")
  22.         Else
  23. Dim str1, str2 As String
  24.             str1 = "user id=sa;password=;data source=AURO-RA4;initial catalog=suganya;server=AURO-RA4"
  25.             con = New SqlConnection(str1)
  26.             Try
  27.                 con.Open()
  28.             Catch
  29.             End Try
  30.             str2 = "update seat1 set b1='bl' where sno='1'"
  31.             cmd = New SqlCommand(str2, con)
  32.             cmd.ExecuteNonQuery()
  33.             con.Close()
  34.             obj5 = Drawing.Color.Blue
  35.         End If
  36.     End Sub`
  37.  
If I run the above, it is getting inserted in the DB but the back color of the button1 in the previous form is not getting changed into "blue" color & still it retains red color.
Apr 2 '08 #1
Share this question for a faster answer!
Share on Google+

Post your reply

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