Back color property in button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sweatha
    New Member
    • Mar 2008
    • 44

    #1

    Back color property in button

    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
    [code=vbnet]
    Protected Sub Button1_Click(B yVal sender As Object, ByVal e As System.EventArg s) Handles Button1.Click
    If Button1.BackCol or = Drawing.Color.F uchsia Then
    Button1.BackCol or = Drawing.Color.R ed
    End If
    End Sub
    [/code]
    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:
    [code=vbnet]
    Protected Sub Button2_Click(B yVal sender As Object, ByVal e As System.EventArg s) Handles Button2.Click
    Dim obj5 As Object
    obj5 = Button1.BackCol or
    Session.Add("b1 ", obj5)
    End Sub
    [/code]
    NEXT FORM:
    [code=vbnet]
    Protected Sub Button1_Click(B yVal sender As Object, ByVal e As System.EventArg s) Handles Button1.Click
    Dim obj5 As Object
    obj5 = CObj(Session("b 1"))
    End Sub
    [/code]
    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
    [code=vbnet]
    Protected Sub Button1_Click(B yVal sender As Object, ByVal e As System.EventArg s) Handles Button1.Click

    Dim obj5 As Object
    obj5 = CObj(Session("b 1"))
    Dim con As SqlConnection
    Dim cmd As SqlCommand
    Dim str As String
    Dim rd As SqlDataReader
    str = "user id=sa;password= ;data source=AURO-RA4;initial catalog=suganya ;server=AURO-RA4"
    con = New SqlConnection(s tr)
    Try
    con.Open()
    Catch
    End Try
    cmd = New SqlCommand
    cmd.Connection = con
    cmd.CommandText = "select count(credit) from credit where credit='" & Trim(TextBox3.T ext.ToString()) & "'"
    Dim cnt As Int16
    cnt = cmd.ExecuteScal ar()
    If cnt <= 0 Then
    Response.Write( "Un authorise user")
    Else
    Dim str1, str2 As String
    str1 = "user id=sa;password= ;data source=AURO-RA4;initial catalog=suganya ;server=AURO-RA4"
    con = New SqlConnection(s tr1)
    Try
    con.Open()
    Catch
    End Try
    str2 = "update seat1 set b1='bl' where sno='1'"
    cmd = New SqlCommand(str2 , con)
    cmd.ExecuteNonQ uery()
    con.Close()
    obj5 = Drawing.Color.B lue
    End If
    End Sub`
    [/code]
    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.
Working...