Click here to Skip to main content
15,867,835 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,

i have a web page contains two option buttons and command button. i need to check the radiobutton.checked value in the command button event. the problem is after clicking the command button the radio button option loose its value, so the if statement will never work. how to prevent this? can anyone help me please?

the code:
VB
Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSave.Click
       
            For i = 1 To tblResult.Rows(0).Cells.Count - 1
                obj = tblResult.Rows(0).Cells(i).Controls(0)
                formIdOption = obj
                If formIdOption.Checked Then
                    formId = CInt(formIdOption.ID)
                    Exit For
                End If
            Next
End Sub


formIdOption.Checked is always false.
Posted
Comments
Jameel VM 31-Jan-13 13:16pm    
where you want to check?Client side or server side?
Brainy Girl 31-Jan-13 13:20pm    
i don't understand your question.
Jameel VM 31-Jan-13 13:25pm    
client side means javascript or jquery(which is executed in the browser itself) and server side is our normal .net code which is executed in the server.you can check both client side and server side.
Brainy Girl 31-Jan-13 13:28pm    
well i'm checking it in the vb code in the button click event but i'm getting false every time
Jameel VM 31-Jan-13 13:30pm    
Please post the html markup also.

1 solution

try this
VB
Dim rb As New RadioButton()
For Each tr As TableRow In QuestionTable.Controls
	For Each tc As TableCell In tr.Controls
		If TypeOf tc.Controls(0) Is RadioButton Then
			rb = DirectCast(tc.Controls(0), RadioButton)
			If rb.Checked Then
				Dim aa As String = rb.ID
			End If
			Exit For
		End If
	Next
Next


Hope this helps
 
Share this answer
 
v2
Comments
Brainy Girl 31-Jan-13 14:01pm    
Thank you for your answer but it does not work.
Jameel VM 31-Jan-13 14:03pm    
did you try this
Brainy Girl 31-Jan-13 14:07pm    
yes i did, rb.Checked is false while i checked it before i clicked the button.
Jameel VM 31-Jan-13 14:05pm    
generate unique id for each radio button
Brainy Girl 31-Jan-13 14:15pm    
yea i'm doing that already, don't you think that the post back makes the radio button looses its value? because the button click is causing the page to refresh.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900