Click here to Skip to main content
12,549,762 members (44,088 online)
Rate this:
Please Sign up or sign in to vote.
See more: ASP.NET
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:
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
End Sub

formIdOption.Checked is always false.
Posted 31-Jan-13 6:46am
JemiM 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.
JemiM 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 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
JemiM 31-Jan-13 13:30pm
Please post the html markup also.
Brainy Girl 31-Jan-13 13:44pm
<form id="form1" runat="server">
<div id="searchView">
<table id="tblSearch" style="width:100%;">

<asp:Label ID="lblSearch" cssclass="labels" runat="server" Text="search">
<asp:TextBox ID="txtTrackingId" cssclass="labels" runat="server">

<asp:Label ID="lblCount" cssclass="labels" runat="server" Text="forms count">
<asp:Label ID="lblCountNumber" CssClass="labels" runat="server" Text="">

<asp:Button ID="btnSearch" cssclass="labels" runat="server" Text="search" />
<asp:Button ID="btnSave" cssclass="labels" runat="server" Text="save" />


<div class="divtable">
<asp:table runat="server" ID="tblResult" Visible="False" >

Brainy Girl 31-Jan-13 13:46pm
note that the radio buttons is being created dynamically in the tblResult table.
JemiM 31-Jan-13 13:50pm
where is your radio button in that markup
Brainy Girl 31-Jan-13 13:55pm
it is being created dynamically in the tblResult table
JemiM 31-Jan-13 13:58pm
ok.i have updated my answer.please try that solution.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

try this
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

Hope this helps
Brainy Girl 31-Jan-13 14:01pm
Thank you for your answer but it does not work.
JemiM 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.
JemiM 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.161021.1 | Last Updated 31 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100