Creating Dynamic ASP.NET Server Controls Using XML

S

Shamin

Hi All,

I'm refering to the code in this article.

http://www.dnzone.com/ShowDetail.asp?NewsId=151

I'm trying to do the same in VB.NET and I'm having problems with
procedure ProcessSurveyResults. I was hoping to get some help on
fixing it. I would really appreciate.

Original C# Code:
while (itr.MoveNext()) {
// get the control name
string controlName = itr.Current.GetAttribute("name", "");
// append question information
sb.Append(controlName);
sb.Append(" : ");
// get the control
object ctrl = FindControl(controlName);
// append the correct filled out information
if (ctrl is TextBox) {
sb.Append(((TextBox)ctrl).Text);
}
if (ctrl is RadioButtonList) {
// the selected item might be null
if (((RadioButtonList)ctrl).SelectedItem != null) {
sb.Append(((RadioButtonList)ctrl).SelectedItem.Value);
}
}
sb.Append(Environment.NewLine);
}

VB.NET CODE:
While itr.MoveNext()
Dim controlName As String =
itr.Current.GetAttribute("name", "")
sb.Append(controlName)
sb.Append(" : ")
Dim ctrl As Object = FindControl(controlName)
If TypeOf ctrl Is TextBox Then
sb.Append(CType(ctrl, TextBox).Text)
End If
If TypeOf ctrl Is RadioButtonList Then
If Not (CType(ctrl, RadioButtonList).SelectedItem Is
Nothing) Then
sb.Append(CType(ctrl,
RadioButtonList).SelectedItem.Value)
End If
End If
sb.Append(Environment.NewLine)
End While

In VB when i debug the code inside the if statements (If TypeOf ctrl
Is ..... Then) is not executed. Any idea on what i'm doing wrong. It
works fine in C#.
 
M

Martin Marinov

I don't know why this code is not executing and don't give any errors but
try this

While itr.MoveNext()
Dim controlName As String =
itr.Current.GetAttribute("name", "")
sb.Append(controlName)
sb.Append(" : ")
Dim ctrl As Object = FindControl(controlName)
If ctrl.GetType().ToString() = "TextBox" Then
sb.Append(CType(ctrl, TextBox).Text)
End If
If ctrl.GetType().ToString() = "RadioButtonList" Then
If Not (CType(ctrl, RadioButtonList).SelectedItem Is
Nothing) Then
sb.Append(CType(ctrl,
RadioButtonList).SelectedItem.Value)
End If
End If
sb.Append(Environment.NewLine)
End While

Hope This Helps
Regards
Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top