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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble with radiobuttons

Status
Not open for further replies.

Weigand

Programmer
Apr 26, 2005
14
US
I am working on updating a web pledge form that's written in asp.net and some jscript. I am having some problems trying to use radio buttons. Here's the jist of what I'm trying to do:

Radio Button Group (no default selected)
• Pledge
• NoPledge

If Radio Button Group = null (no selection is made)
Required Field Validator
“Please select a radiobutton”

Onclick “Pledge” radio button
Display a dropdownlist of gifts

If dropdownlist = “” (no selection is made)
Required Field Validator
“Please select a gift”

Onclick “NoPledge” radio button
Hide dropdownlist of gifts

Is it possible to get radio buttons to behave like this? I am new to VB.net and working very hard to meet a deadline.

Any help would be greatly appreciated.
 
Just use a radio button list and then on the SelectedIndexChange (remember to set the AutoPostBack to True) use something like:
Code:
        If RadioButtonList1.Items(0).Selected = True Then
            DropDownList1.Enabled = True
        Else
            DropDownList1.Enabled = False
        End If

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
Use the AutoPostBack property = True, then put code in then SelectedIndexChange sub...

"...we both know I'm training to become a cagefighter...see what happens if you try 'n hit me..."
 
Here's what I tried:

<asp:RadioButtonList id="grpRadPrems" runat="server" Width="288px" AutoPostBack="True">
<asp:ListItem Value="radNoPrem">No Gift<asp:ListItem>
<asp:ListItem Value="radYesPrem">Gift<asp:ListItem>
</asp:RadioButtonList>



Private Sub grpRadPrems_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles grpRadPrems.SelectedIndexChanged

If grpRadPrems.Items(0).Selected = True Then
cboPremium.Enabled = True
Else
cboPremium.Enabled = False

End If
End Sub


The page refreshes (which I was just looking for the Drop DownList to appear) and nothing happens. Any ideas of what I'm doing wrong...or where to find some help?
 
From what I can see that should work. Here's what I have just in case you missed anything:
Code:
<asp:DropDownList id="DropDownList1" style="Z-INDEX: 104; LEFT: 304px; POSITION: absolute; TOP: 336px"
				runat="server"></asp:DropDownList>
			<asp:RadioButtonList id="RadioButtonList1" runat="server" AutoPostBack="True">
				<asp:ListItem Value="Yes">Yes</asp:ListItem>
				<asp:ListItem Value="No">No</asp:ListItem>
			</asp:RadioButtonList>
and
Code:
    Private Sub RadioButtonList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButtonList1.SelectedIndexChanged
        If RadioButtonList1.Items(0).Selected = True Then
            DropDownList1.Enabled = True
        Else
            DropDownList1.Enabled = False
        End If
    End Sub
and that works perfectly.

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
On this page before I added the radiobuttons, there was a checkbox to control displaying the dropdownlist. It used some javascript to control this feature:

//Disable premium selection if NoPremiums is checked
function NoPremium( p ){
var doc = TheForm()
var a = document.getElementById("lnkSearch");

if( p == "radNoPremium" ){
doc.cboPremium.value = "";
HideCtrl(doc.cboPremium);
HideCtrl(a);
}
else{
ViewCtrl(doc.cboPremium);
ViewCtrl(a);
}
}


//hide the control on the screen
function HideCtrl( obj ){
//if(obj.style.display != 'none')
obj.style.display = 'none';
//else
// obj.style.display = '';
}

function ViewCtrl( obj ){
obj.style.display = '';
}


Could this have anything to do with the broken functionality?
 
Possibly. I would remove all scripts and references you have to those controls and just use the code I provided above.

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
Thanks!

I finally got it to work, but when I click on a radiobutton the page refreshed to the top to the page. Any suggestions?
 
Yep - set the smartNavigation property of the page to True

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
Thanks!!!

One more thing...

When I select the "nogift" radiobutton the dropdownlist disapears, then I select the other radiobutton and the page refreshes. Is this normal?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top