473,769 Members | 2,402 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get value of dynamic control radio button after postback

2 New Member
Hi guys,

I am looking into create a dynamic survey as posted in Get User Input From Dynamic Controls but with some different environment
Below is what i am trying to do:
First when the user click the button, it will populate a dynamic table with radio button for the survey questionnaire
However, i was unable to get its value (for score calculation) after clicking the submit button
Beside i am using an ajax extension (updatePanel) for the development
I have been look into viewstate but i hv no idea with it.

Does anyone have any ideas?

Here i included some of my code:

part of code in page
Expand|Select|Wrap|Line Numbers
  1.  
  2.         <asp:UpdatePanel ID="UpdatePanel1" runat="server">
  3.             <ContentTemplate>
  4.                 <asp:Button ID="btnTest" runat="server" Text="Take Test" OnClick="btnTest_Click" Visible="False" />
  5.                 <asp:Label ID="lblTestErrMsg" runat="server" 
  6.  
  7.     ForeColor="Red"></asp:Label><br />
  8.                     <table id="tblTest" runat="server" style="width: 100%">
  9.                         <tr>
  10.                             <td>
  11.                              <asp:PlaceHolder ID="phQuestionnaire" runat="server"></asp:PlaceHolder>
  12.                                 <br />
  13.                                 </td>
  14.                         </tr>
  15.                         <tr>
  16.                             <td>
  17.                                 </td>
  18.                         </tr>
  19.                         <tr>
  20.                             <td>
  21.                                 <asp:Label ID="lblResult" runat="server"></asp:Label></td>
  22.                         </tr>
  23.                         <tr>
  24.                             <td>
  25.                             </td>
  26.                         </tr>
  27.                     </table>
  28.                 </ContentTemplate>
  29.             </asp:UpdatePanel>
  30.  
Populate Dynamic Table function
* v_dtTable and v_dtTable2 contains the data from database

Expand|Select|Wrap|Line Numbers
  1.    Private Sub CreateDynamicTable(ByVal v_dtTable As Data.DataTable, ByVal v_dtTable2 As Data.DataTable)
  2.         Me.phQuestionnaire.Controls.Clear()
  3.         Dim cols As Integer = v_dtTable.Rows.Count + 2
  4.         Dim rows As Integer = v_dtTable2.Rows.Count + 1
  5.         Dim mid As Integer = v_dtTable.Rows.Count / 2
  6.  
  7.         Dim tbl As Table = New Table()
  8.         tbl.ID = "tblQs"
  9.         tbl.BorderWidth = 1
  10.         tbl.CellPadding = 0
  11.         tbl.CellSpacing = 0
  12.         tbl.Width = 500
  13.         tbl.EnableViewState = True
  14.  
  15.         Me.phQuestionnaire.Controls.Add(tbl)
  16.         For i As Integer = 0 To rows - 1
  17.             Dim tr As TableRow = New TableRow()
  18.             Dim rowCnt As Integer = 1
  19.             Dim colCnt As Integer = 0
  20.  
  21.             For j As Integer = 0 To cols - 1
  22.                 Dim tc As TableCell = New TableCell()
  23.                 tc.BorderWidth = 1
  24.                 Dim lbl As Label = New Label()
  25.                 Dim bol As Boolean = False
  26.  
  27.                 If i = 0 Then       
  28.                     If j = 0 Then
  29.                         tc.Text = "No."
  30.  
  31.                     ElseIf j = 1 Then
  32.                         tc.Text = "Question"
  33.  
  34.                     Else
  35.                         tc.Text = v_dtTable.Rows(j - 2).Item("scoreName")
  36.                         tc.HorizontalAlign = HorizontalAlign.Center
  37.                     End If
  38.                     tc.BackColor = Drawing.Color.DeepSkyBlue
  39.                     tc.ForeColor = Drawing.Color.White
  40.                 Else
  41.                     If v_dtTable2.Rows(i - 1).Item("isHeader") Then
  42.                         bol = True
  43.                         tc.Text = v_dtTable2.Rows(i - 1).Item("TestQuestion")
  44.                         tc.Style("font-weight") = "bold"
  45.  
  46.                     ElseIf j = 0 Then
  47.                         tc.Text = rowCnt
  48.                         rowCnt += 1
  49.  
  50.                     ElseIf j = 1 Then
  51.                         tc.Text = v_dtTable2.Rows(i - 1).Item("TestQuestion")
  52.  
  53.                     Else
  54.                         Dim rBtn As RadioButton = New RadioButton
  55.                         rBtn.GroupName = "rBtn" & rowCnt
  56.                         rBtn.ID = "rBtn_" & rowCnt & "_" & colCnt
  57.                         rBtn.InputAttributes("value") = v_dtTable.Rows(j - 2).Item("scoreValue")
  58.                         colCnt += 1
  59.                         If j = mid + 2 Then
  60.                             rBtn.Checked = True
  61.                         End If
  62.  
  63.                         tc.Controls.Add(rBtn)
  64.                         tc.HorizontalAlign = HorizontalAlign.Center
  65.                     End If
  66.                 End If
  67.  
  68.                 If bol Then
  69.                     tc.ColumnSpan = cols - 1
  70.                     tr.Cells.Add(tc)
  71.                     Exit For
  72.                 Else
  73.                     tr.Cells.Add(tc)
  74.                 End If
  75.             Next j
  76.  
  77.             tbl.Rows.Add(tr)                              
  78.         Next i
  79.  
  80.     End Sub
  81.  
Calculate Score function
Expand|Select|Wrap|Line Numbers
  1.         Private Sub subCalculateScore()
  2.         Dim tblQs As Table = CType(Me.phQuestionnaire.FindControl("tblQs"), Table)
  3.         Dim rb As New RadioButton
  4.         Dim score As Integer = 0
  5.  
  6.         If Me.phQuestionnaire.FindControl("tblQs") Is Nothing Then
  7.         Else
  8.             For Each tr As TableRow In tblQs.Rows
  9.                 For Each tc As TableCell In tr.Cells
  10.                     For Each c As Control In tc.Controls
  11.                         If c.GetType.ToString = rb.GetType.ToString Then
  12.                             Dim rBtn As RadioButton = CType(c, RadioButton)
  13.                             If rBtn.Checked Then
  14.                                 Dim strScore As String = rBtn.InputAttributes("value")
  15.                                 score += CInt(strScore)
  16.                             End If
  17.                         End If
  18.                     Next
  19.                 Next
  20.             Next
  21.         End If
  22.  
  23.         Me.Label1.Text = score
  24.     End Sub
  25.  
Jul 7 '09
12 24814
sharifee
9 New Member
create only one hidden field . if u know XML then it is very easy. just write XML tags to hidden field and you can access every value or attribute of the tag you have written to hidden field.
Sep 25 '09 #11
Gaigoi
4 New Member
Thank! Im using the placeholder to solved my question.
Sep 27 '09 #12
Frinavale
9,735 Recognized Expert Moderator Expert
I have no idea what your problem was, but typically you don't need to use a hidden field in order to determine the value of a radio button. A "place holder" in asp.net wouldn't really help you either since a placeholder is a container used to store server controls that are dynamically added to the Web page.

I'm assuming that you've solved your mysterious problem but I just wanted to make sure that whatever you've done isn't going to confuse someone else looking for help with retrieving the value of a dynamically created radio button.

Normally you would use the FindControl method to retrieve the dynamically created radio button (or any dynamically generated control). Once you have retrieved the dynamic control you can retrieve it's value.

-Frinny
Sep 28 '09 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

4
4133
by: mitch-co2 | last post by:
What I am trying to do is when someone clicks on the YES radio button I want the text field called MYTEXT to equal the text field named DATE. The below code works as long as I do NOT UN-COMMENT the NO radio button, once I do that it will not work. Any help would be greatly appreciated. Mitch
5
17712
by: johnsuth | last post by:
I want to produce a trivial demonstration of dynamic modification. I thought that pressing a button might change its color. I studied O'Reillys books and successfully created the button with a fancy style, but the onclick fails to do anything no matter what permutation of parameters I try. <input type=button style=background-color:yellow;color:blue;font-family:Arial;font-style:italic;font-weight:bold name="xyz" value="CHANGE COLOUR"...
5
2527
by: PCH | last post by:
I have an c# asp.net (.net 1.1) web page, viewstate on. The problem I am having is on the button click postback to update. Heres the situation: I have an asp table that has 1 header row. On load I loop through a count, say 0 to 3, and dynamically build rows, into the asp table.
2
1549
by: darrel | last post by:
I'm using some standard HTML radio buttons (to allow finer javascript interaction) on a web page and would like to catch the selected item on postback. Since they are all ID's uniquely, is there a way to grab only the selected item's value? Or do I need to write an if/then statement to figure out which one is selected? Sample: <input runat="server" id="radio1" name="category" /> <input runat="server" id="radio2" name="category" />
8
3767
by: david | last post by:
I have developed a web form by using visual Studio. My question is: (1) what is the problem? (2) what is right way to do it? In the form, there are labels with id: lblWear, lblColor, and lblQuality. Now I need to assign values to those label dynamically. I have JavaScript: function regTriples(id){ if (id==1){
11
3151
by: saurabh | last post by:
Can anybody tell me how to change the value of an html control from the c#.... eg i hv one asp.net radio button control and one html hidden variable... so on page load in case the radio button is checked i want to set this hidden variable to 1 else 0... I am not getting what to write in Page_Load(object sender, System.EventArgs e) function to change the value of this html variable...
1
5467
by: Mufasa | last post by:
I have a couple of radio buttons that make various things appear/disappear on the screen through JavaScript. All works great. Problem is I'll click a radio button, something will appear, I reload the page for other reasons and the item disappears. The reason it disappears is I have to set the state initially to invisible so it doesn't show up initially. The radio buttons are html radio buttons not aspx radio buttons so I can have the...
4
1970
by: mcelary | last post by:
When the user clicks a radio button it creates a postback where I add a button control dynamically. My problem is I cannot get the dynamically added button to work with on an click event. The button was created in code behind page. Public Sub rosterAddControls() Dim myBtn As New Button() myBtn.Style.Item("z-index") = "100" myBtn.Style.Item("position") = "absolute" myBtn.Style.Item("top") = (x - 30) & "px" ...
13
10723
by: tommymo | last post by:
Hi everyone I'm new to this site and the world of ASP.Net C# programming. I have been learning controls and integrating them with a SQL database. So far I have been able to move along and understand static controls. However I would like to move on to attempt to create some dynamic controls. So I set out to work with a radiobuttonlist questionnaire. I have a database and in that DB I have 2 tables one which holds the questions and the other...
0
9586
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10210
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10043
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9990
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7406
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2814
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.