Enflow
asked on
Create ASP.net VB.code Equal To JavaScript Loop Function
Using Framework...
ASP.NET Regular Web Form
Using Code Behind...
VB.net & JavaScript & JQuery
My Issue...
I Need VB.code replacement for the following JavaScript Function --
(JavaScript Function may not be Syntactically Correct Since I Slightly modified its structure)
This JavaScript Function is PASSED the GROUPNAME of a group of Radio buttons...
It loops thru all the individual radio buttons of that Group of buttons via that GROUPNAME...
and ihen it should return the one radio button that was selected...
I need this in Server Side vb.net code instead of client side JavaScript code...
I have already laid out 35 Groups of Radio buttons each with 2, 3 or 5 individual choices -- already built in my ASP.net form so doing Radio Button List is now past as option
Any Experts have or can create this vb.net code equal to the JS code ??
thanks... CJ
ASP.NET Regular Web Form
Using Code Behind...
VB.net & JavaScript & JQuery
My Issue...
I Need VB.code replacement for the following JavaScript Function --
(JavaScript Function may not be Syntactically Correct Since I Slightly modified its structure)
function myFunc(RBG) {
var rbGrp = RBG;
var myVal;
var radioButtons = document.getElementsByName(rbGrp);
for (var x = 0; x < radioButtons.length; x ++) {
if (radioButtons[x].checked) {
myVal = radioButtons[x].id);
return myVal;
}
}
}
This JavaScript Function is PASSED the GROUPNAME of a group of Radio buttons...
It loops thru all the individual radio buttons of that Group of buttons via that GROUPNAME...
and ihen it should return the one radio button that was selected...
I need this in Server Side vb.net code instead of client side JavaScript code...
I have already laid out 35 Groups of Radio buttons each with 2, 3 or 5 individual choices -- already built in my ASP.net form so doing Radio Button List is now past as option
Any Experts have or can create this vb.net code equal to the JS code ??
thanks... CJ
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Code example posted.
ASKER
@Ron...
Thank you for your code... Looks very nicely done...
I am not using RadioButtonList controls...
But This Should work for RadioButton controls with Each having an Unique Group Name for EACH Group of them... with a slight mod on control object specification ????
For example here is One Group of RadioButton controls...
Thank you for your code... Looks very nicely done...
I am not using RadioButtonList controls...
But This Should work for RadioButton controls with Each having an Unique Group Name for EACH Group of them... with a slight mod on control object specification ????
For example here is One Group of RadioButton controls...
<div class="divTableRow">
<div class="divTableCellTwo_12Pct">Gender:<strong>*</strong></div>
<div class="divTableCellTwo_38Pct">
<asp:RadioButton ID="GD_1_M" runat="server" GroupName="Gender_1" Text="Male" ToolTip="M" />
<asp:RadioButton ID="GD_1_F" runat="server" GroupName="Gender_1" Text="Female" ToolTip="F" />
</div>
<div class="divTableCellTwo_12Pct">Last4 SSN:<strong>*</strong></div>
<div class="divTableCellTwo_38Pct">
<asp:TextBox ID="Last4_SS_1" runat="server" Height="25px" Width="340px" Wrap="False" BackColor="#EAF4FF" Font-Size="Large" BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" MaxLength="4" ToolTip="Enter Last 4 Numbers of Social Security Number"></asp:TextBox>
</div>
</div>
You can do them individually ... or loop through the child controls attributes within each div to check for the group.
GD_1_M.Checked ..is the simplest way to see if it's checked individually.
GD_1_M.Checked ..is the simplest way to see if it's checked individually.
ASKER
@Ron... Ok... Thanks for the Help...
Seems like RadioButtonLists data are much easier to parse then the individual RBs even with unique Group Names... CJ
Seems like RadioButtonLists data are much easier to parse then the individual RBs even with unique Group Names... CJ
Sorry for the late response but you can do something like this
You can call the function and verify if is on the Group Name and if is on that group name then get what is checked. Also remember that this is for a simple control collection on the root of the page. if you have master page or any other control that has children controls on the page you need to loop through those recursively
Private Function RadioValue(ByVal GroupName As String) As String
Dim RdValue As String = String.Empty
For Each RdButton As Control In Page.Controls
If TypeOf (RdButton) Is RadioButton Then
If TryCast(RdButton, RadioButton).GroupName = GroupName Then
If TryCast(RdButton, RadioButton).Checked Then
RdValue = TryCast(RdButton, RadioButton).Text
Exit For
End If
End If
End If
Next
Return RdValue
End Function
You can call the function and verify if is on the Group Name and if is on that group name then get what is checked. Also remember that this is for a simple control collection on the root of the page. if you have master page or any other control that has children controls on the page you need to loop through those recursively
ASKER
@J. Rodriguez...
Yes... I appreciate you coming in right at the buzzer... :o) --
I will test this out... I was hoping someone would have this in their back pocket... ... Yes, I am trying to loop thru all the RButtons on one long Web Form by GroupName and pull the selected text value out for each RB Group... To insert values into variables for the Insert Info submit code into my SQL Server DB...
Thanks for the help... CJ
Yes... I appreciate you coming in right at the buzzer... :o) --
I will test this out... I was hoping someone would have this in their back pocket... ... Yes, I am trying to loop thru all the RButtons on one long Web Form by GroupName and pull the selected text value out for each RB Group... To insert values into variables for the Insert Info submit code into my SQL Server DB...
Thanks for the help... CJ
Try it yourself, post your code and any errors and we can point out improvements and what you are doing wrong.