Click here to Skip to main content
Rate this: bad
good
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
            Next
End Sub
 
formIdOption.Checked is always false.
Posted 31-Jan-13 6:46am
Comments
JemiM at 31-Jan-13 13:16pm
   
where you want to check?Client side or server side?
Brainy Girl at 31-Jan-13 13:20pm
   
i don't understand your question.
JemiM at 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 at 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 at 31-Jan-13 13:30pm
   
Please post the html markup also.
Brainy Girl at 31-Jan-13 13:44pm
   
<body>
<form id="form1" runat="server">
<div id="searchView">
<table id="tblSearch" style="width:100%;">
<tr>

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

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

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

</div>

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

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

1 solution

Rate this: bad
good
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
	Next
Next
 
Hope this helps
  Permalink  
v2
Comments
Brainy Girl at 31-Jan-13 14:01pm
   
Thank you for your answer but it does not work.
JemiM at 31-Jan-13 14:03pm
   
did you try this
Brainy Girl at 31-Jan-13 14:07pm
   
yes i did, rb.Checked is false while i checked it before i clicked the button.
JemiM at 31-Jan-13 14:05pm
   
generate unique id for each radio button
Brainy Girl at 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
0 OriginalGriff 6,034
1 Sergey Alexandrovich Kryukov 4,838
2 Peter Leow 3,129
3 Maciej Los 3,079
4 DamithSL 2,465


Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 31 Jan 2013
Copyright © CodeProject, 1999-2014
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