passing server control object to generic object (C# --> VB.NET)

lounge56

Newcomer
Joined
Feb 5, 2004
Messages
14
Hello! I am building an application which dynamically assembles a web form and its server controls using an XML template and formatting it with XSL. What I have done so far is in C#, but now I am required to convert it to VB.NET. The way it works is that I have an .aspx page w. an <asp:Placeholder> which serves as a container for the dynamically created server controls. I have a function that reads values from XML, and depending on these, the XSL formats the content and the output is displayed in the web form. When I submit the web form with the selected answers are extracted from each question in the following way in C#:

1. A While Loop goes through the XML and identifies what type of server control (along with its name/ID) will the data be extracted from.

2. The dynamically generated server control is identified in the submitted form and the selected value(s) are obtained.

The following funtion (excerpt) performs what I just described:


private void ProcessSurveyResults()
{
// Load the data source
XPathDocument surveyDoc = new XPathDocument(Server.MapPath("ExSurvey.xml"));
// create an iterator
XPathNodeIterator itr = surveyDoc.CreateNavigator().Select("//question");
// string builder for survey body
System.Text.StringBuilder sb;
sb = new System.Text.StringBuilder();
// submission information
sb.Append("Survey submitted on " + DateTime.Now + Environment.NewLine);
// foreach question
while (itr.MoveNext())
{
// get the control name
string controlName = itr.Current.GetAttribute("name", "");
// append question information
sb.Append(controlName);
sb.Append(" : ");
// get the control
//********* this is where I run into trouble in VB.NET
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);
}
}


In this excerpt, I marked where I have trouble translating my source code into VB by placeing the comment "this is where I run into trouble in VB.NET". From what I have seen:

1. I think FindFunction() is at a different hierarchy level for VB.NET. The result is that it is used incorrectly if written tried to be used in the same way in VB.NET, resulting in "Nothing" returned.

2. Even if I did figure out how to use FindControl() for this case in VB.NET, I am not sure if I can pass this object to a generic object variable as I did in my C# code.

Any help with the particular C# --> VB.NET translation of this line of code would be greatly appreaciated. Pls. let me know if you need to know anything else.

Than you!

-ricardo 8~)
 
Back
Top