Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

disable imagebutton problems

Status
Not open for further replies.

lin73

Programmer
Feb 17, 2006
110
SE
Hi

I use asp.net 2 and have one asp:sqldatasource and one asp:radiobuttonlist on my aspx page, the radiobuttonlist is filled with data from my sql server. I further have a imagebutton that the user should click when he have made a choise from the radiobuttonlist. But the problem is that its not always the radiobutton list gets values from the database. This depends on what ID querystring is being passed. And when there are no radiobutton items to choose from I would like to disable the imagebutton. How can I do that in my codebehind? I tryed to use this...


Code:
        If RadioButtonList2.Items.Count > 0 Then
            ImageButton1.Enabled = True
        Else
            ImageButton1.Enabled = False
        End If

But that always disable the imagebutton.


Regards
 
what do you mean it doesn't work.. If there is at least one item it will be enabled. Not sure what the problem is.
 
I mean that there are scenarious when there are no items at all.....

 
Ok so what is the problem..? If no items exist then you disable the button
 
My problem is that I have a imagebutton click event arg on my page and I there check the radiobottons value, but if no radiobuttonlist exsist I get a null reference error message.
 
I still can't figure out what your really trying to do??

you said your trying to disable a button if items.count < 0 correct? why would you put that arg on your button click event if the button can get disabled??

 
I want to disable the button it there are no items in the radiobuttonlist because the button redirect the user to another page where a querystring value is being parsed the value that is being parsed is a value from the radíobuttonlist. But if the radiobuttonlist doesnt have any values I can't retreive any values from it and I get an error if I try to check it's value beacuse it doesn't exsist.
 
Again you are being very unclear. Your code does what it should do, If there are no items then disable the button. It can't be any more straight forward than that
 
I think you need to break up your problem into two sections..

first of all you said


I want to disable the button it there are no items in the radiobuttonlist because the button redirect the user to another page where a querystring value is being parsed the value that is being parsed is a value from the radíobuttonlist.

simple, do what you are currently doing and that should work. but again, I would use a select case statement for that. if's can sometimes be buggy depending on what your doing.

But if the radiobuttonlist doesnt have any values I can't retreive any values from it and I get an error if I try to check it's value beacuse it doesn't exsist.

that part is where your very unclear. as jbenson said, It can't be any more straight forward than that...




 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top