473,414 Members | 1,862 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Creating Dynamic ASP.NET Server Controls Using XML

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.Val ue);
}
}
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#.
Nov 18 '05 #1
1 1637
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
"Shamin" <sh******@hotmail.com> wrote in message
news:44**************************@posting.google.c om...
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.Val ue);
}
}
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#.

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Matthew Clubb | last post by:
Hi, I need help developing an expanding form I've decided that a use of PHP, Mysql and Javascript is the best platform for creating a selection of database interfaces which I'm trying to build...
4
by: Venus | last post by:
Hello, Thanks for your reply. I understand that a control can be created dynamically in several ways: 1) using StringBuilder 2) using Controls.Add 3) using ASP PlaceHolder But this is just...
0
by: Venus | last post by:
Hello, After trying some ways to do it I wanted to use something like the code below but for some reason is not working (I have to generate the entire form dynamically (not only the controls)):...
6
by: Glenn Owens | last post by:
I have an ASP.Net page on which there are serveral static controls (listboxes, radiobuttonlist and textboxes). These controls are used to create criteria from which the code-behind will dynamically...
1
by: Hasani \(remove nospam\) | last post by:
The way the system works is, you create a user control (ascx) that will be a template and must implement the interface IPageTemplate. You then create one or more user controls (ascx) that implement...
2
by: Matt | last post by:
Hi, Can someone provide some information on how to create a control dynamically based on the contents of another dynamic control. In my experience, all dynamic controls must be created in the...
2
by: Patrick | last post by:
I want to define a set of web-form templates in XML and render the equivalent web-form with ASP.NET, then process any input server controls on the form. Reading the XML file from Page_load is...
7
by: Varangian | last post by:
Hello is creating controls at runtime the same as designtime ? will a page be faster if controls are created at designtime rather than at runtime ? If so why ? thanks :)
5
by: Guillaume BRAUX | last post by:
Hello, What I want to do is to add a userControl to a form class witch is a different class from the one the button is generated. For example, I want to instanciate a label in "class1" and add...
9
by: Tarscher | last post by:
hi all, I have this seemingly simple problem. I have lost a lot of time on it though. When a user selects a value from a dropdownlist (static control) a dynamic control is generated. I have...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.