I need some assistance with disabling web control button. First, i need to check if the value related to the button is in the listbox. This is done.

If the item is in the listbox, disable the button. I am thinking the possibility of using a loop statement. However, i do not know how to write it to check if the item related to the button matched before disabling button.

Recommended Answers

All 5 Replies

Are you doing this client-side, or server-side?

What do you mean by "disable"? Show, but have no effect when clicked? Or, remove the button completely?

I have difficulty understanding your last sentence. Could you rephrase the question?

Server Side.

I am doing a movie booking page and the seats are represented by web control buttons. They are to be disabled when the seats booked values are listed in a listbox known as listbox_seatsbooked.

From the listbox_seatsbooked, it is suppose to check if the value of the button matches the ones listed in the listbox to disable the button from being clicked again. (Seats can't be booked) again.

I have included an image of how it looks for better clarifications.
[IMG]http://i1.tinypic.com/ncim4l.jpg[/IMG]

' Disable the Add button if the ListBox control already contains the item.

Dim name as string
Dim item As ListItem = listbox_seatsbooked.Items.FindByText(name)
If Not item Is Nothing Then

a1.Enabled = False
Else
a1.Enabled = True

End If

I tried writing this. However, its not executing.

you made a small error... you didnt set 'name' to anything.

Dim name as string
Dim item As ListItem = listbox_seatsbooked.Items.FindByText(name)
If Not item Is Nothing Then

need to be

Dim name as string = thebutton.tag  
'that is assuming you set the tag to be the seat number such as A1 on btna1, A2 on btna2 etc. 
Dim item As ListItem = listbox_seatsbooked.Items.FindByText(name)
If Not item Is Nothing Then

Hi f1_fan, thanks for ur assistance.

I cannot find a declaration known as .tag in asp.net (codebehind vb.net). I tried using C# converter to VB.net.

Any suggestions?

you made a small error... you didnt set 'name' to anything.

need to be

Dim name as string = thebutton.tag  
'that is assuming you set the tag to be the seat number such as A1 on btna1, A2 on btna2 etc. 
Dim item As ListItem = listbox_seatsbooked.Items.FindByText(name)
If Not item Is Nothing Then
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.