Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB.NET
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
VB.NET General VB.NET discussions for issues that don't fall into other VB.NET forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 13th, 2006, 01:36 PM
Banned
Points: 1,561, Level: 16
Points: 1,561, Level: 16 Points: 1,561, Level: 16 Points: 1,561, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2005
Location: , , .
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help w/conversion from C# to VB.NET

I found a great article titled "Creating Dynamic ASP.NET Server Controls Using XML" at http://www.dnzone.com/showDetail.asp...Ehtm&offset=10.

But all of the code was written in C#. I've tried using the C# to VB.NET conversion tool at http://www.kamalpatel.net/ConvertCSharp2VB.aspx, but I'm still running into errors. This is the latest error:

BC30205: End of statement expected.
Line 19:
Line 20: Public Class WebForm1
Line 21: Inherits System.Web.UI.Page Public class WebForm1 : System.Web.UI.Page
Line 22:
Line 23: Protected Title As System.Web.UI.WebControls.TextBox

And since I don't know C#, and I'm a newbie to VB.NET, I'm not sure how to proceed. If anyone can give me some help and/or some converted code, that would be great. Thanks for any help.

Original C# Code:
Code:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

// add references for XSLT
using System.Xml;
using System.Xml.Xsl;
using System.Xml.XPath;

// add references for Streams
using System.IO;

namespace CustomSurveys
{
    /// <summary>
    ///        This is a custom survey page, where the questions
    ///        are created at runtime
    /// </summary>
    public class WebForm1 : System.Web.UI.Page
    {
        protected System.Web.UI.WebControls.TextBox Title;
        protected System.Web.UI.WebControls.PlaceHolder survey;
        protected System.Web.UI.WebControls.Literal ThankYouLabel;

        private void Page_Load(object sender, System.EventArgs e)
        {
            if (IsPostBack) {
                ProcessSurveyResults();
                survey.Visible = false;
                ThankYouLabel.Visible = true;
            } else {
                survey.Visible = true;
                ThankYouLabel.Visible = false;
            }
        }

        private void CreateSurvey() {
            // Load the data source
            XPathDocument surveyDoc = new XPathDocument(Server.MapPath("ExSurvey.xml"));

            // Load the xslt to do the transformations
            XslTransform transform = new XslTransform();
            transform.Load(Server.MapPath("MakeControls.xslt"));

            // Get the transformed result
            StringWriter sw = new StringWriter();
            transform.Transform(surveyDoc, null, sw);
            string result = sw.ToString();

            // remove the namespace attribute
            result = result.Replace("xmlns:asp=\"remove\"", "");

            // parse the control(s) and add it to the page
            Control ctrl = Page.ParseControl(result);
            survey.Controls.Add(ctrl);
        }

        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
                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);
            }
            string body = sb.ToString();

            // send the results
            System.Web.Mail.SmtpMail.SmtpServer = "your.smtp.server";
            System.Web.Mail.SmtpMail.Send("survey@somewhere.com", "your@address.com", "Survey result", body);
        }

        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            CreateSurvey();
            base.OnInit(e);
        }

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {    
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion
    }
}
[b]Converted VB.NET Code:
Code:
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls

' add references for XSLT
Imports System.Xml
Imports System.Xml.Xsl
Imports System.Xml.XPath
 
' add references for Streams
Imports System.IO

    Public Class WebForm1
     Inherits System.Web.UI.Page    Public class WebForm1 : System.Web.UI.Page

        Protected Title As System.Web.UI.WebControls.TextBox
        Protected survey As System.Web.UI.WebControls.PlaceHolder
        Protected ThankYouLabel As System.Web.UI.WebControls.Literal

        '***THIS SECTION BELOW WOULD NOT CONVERT***
        private void Page_Load(Object sender, System.EventArgs e)
        {
            if (IsPostBack) {
                ProcessSurveyResults();
                survey.Visible = false;
                ThankYouLabel.Visible = true;
            } else {
                survey.Visible = true;
                ThankYouLabel.Visible = false;
            }
        }
        '***THIS SECTION ABOVE WOULD NOT CONVERT***

        Private  Sub CreateSurvey()
            ' Load the data source
            Dim surveyDoc As XPathDocument =  New XPathDocument(Server.MapPath("ExSurvey.xml")) 
 
            ' Load the xslt to do the transformations
            Dim transform As XslTransform =  New XslTransform() 
            transform.Load(Server.MapPath("MakeControls.xslt"))
 
            ' Get the transformed result
            Dim sw As StringWriter =  New StringWriter() 
            transform.Transform(surveyDoc, Nothing, sw)
            Dim result As String =  sw.ToString() 
 
            ' remove the namespace attribute
            result = result.Replace("xmlns:asp=\"remove\"", "")
 
            ' parse the control(s) and add it to the page
            Dim ctrl As Control =  Page.ParseControl(result) 
            survey.Controls.Add(ctrl)
        End Sub

        Private  Sub ProcessSurveyResults()
            ' Load the data source
            Dim surveyDoc As XPathDocument =  New XPathDocument(Server.MapPath("ExSurvey.xml")) 
            ' create an iterator
            Dim itr As XPathNodeIterator =  surveyDoc.CreateNavigator().Select("//question") 
            ' string builder for survey body
            Dim sb As System.Text.StringBuilder
            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
                Dim controlName As String =  itr.Current.GetAttribute("name","") 
                ' append question information
                sb.Append(controlName)
                sb.Append(" : ")
                ' get the control
                Dim ctrl As Object =  FindControl(controlName) 
                ' append the correct filled out information
                If TypeOf ctrl Is TextBox Then
                    sb.Append((CType(ctrl, TextBox)).Text)
                End If
                If TypeOf ctrl Is RadioButtonList Then
                    ' the selected item might be null
                    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
            Dim body As String =  sb.ToString() 
 
            ' send the results
            System.Web.Mail.SmtpMail.SmtpServer = "your.smtp.server"
            System.Web.Mail.SmtpMail.Send("survey@somewhere.com", "your@address.com", "Survey result", body)
        End Sub

        #Region 'Web Form Designer generated code
        Overrides Protected  Sub OnInit"(ByVal e As EventArgs)
            '
            ' CODEGEN: This call is required by the ASP.NET Web Form Designer.
            '
            InitializeComponent()
            CreateSurvey()
            MyBase.OnInit(e)
        End Sub

        Private  Sub InitializeComponent()    
            Me.Load += New System.EventHandler(Me.Page_Load)
 
        End Sub
        #End Region
    End Class


KWilliams
Reply With Quote
  #2 (permalink)  
Old October 13th, 2006, 01:55 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

First remove the Public class Webform1 : System.Web.UI.Page from this line:

Inherits System.Web.UI.Page Public class WebForm1 : System.Web.UI.Page

Your class should now look like this:
Code:
Public Class WebForm1
     Inherits System.Web.UI.Page    
      Protected Title As System.Web.UI.WebControls.TextBox
      //code
this
Code:
        '***THIS SECTION BELOW WOULD NOT CONVERT***
        private void Page_Load(Object sender, System.EventArgs e)
        {
            if (IsPostBack) {
                ProcessSurveyResults();
                survey.Visible = false;
                ThankYouLabel.Visible = true;
            } else {
                survey.Visible = true;
                ThankYouLabel.Visible = false;
            }
        }
        '***THIS SECTION ABOVE WOULD NOT CONVERT***
becomes

Code:
Private Sub Page_Load(ByVal sender as System.Object, ByVal e as System.EventArgs)

If Page.IsPostBack then
    ProcessSurveyResults()
    survey.Visible = false
    ThankYouLabel.Visible = true
Else
    survey.Visible = true
    ThankYouLabel.Visible = false
End If
End Sub

And, IMHO you should learn C# as well as VB.NET.

hth


-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
Reply With Quote
  #3 (permalink)  
Old October 13th, 2006, 03:52 PM
Banned
Points: 1,561, Level: 16
Points: 1,561, Level: 16 Points: 1,561, Level: 16 Points: 1,561, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2005
Location: , , .
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the info dparsons. I'm almost done debugging my version of the code, and hopefully I'll have a working version soon. I really appreciate your help, and I will definitely take your advice about also learning C#. Have a good weekend.

KWilliams
Reply With Quote
  #4 (permalink)  
Old October 13th, 2006, 04:01 PM
Banned
Points: 1,561, Level: 16
Points: 1,561, Level: 16 Points: 1,561, Level: 16 Points: 1,561, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2005
Location: , , .
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, these are the last two errors I'm getting:

ERROR #1
BC30516: Overload resolution failed because no accessible 'Replace' accepts this number of arguments.
Line 53:
Line 54: ' remove the namespace attribute
Line 55: result = result.Replace("xmlns:asp=\"remove\"", "")
Line 56:
Line 57: ' parse the control(s) and add it to the page

ERROR #2
BC32022: 'Public Event Load(sender As Object, e As System.EventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.
Line 109:
Line 110: Private Sub InitializeComponent()
Line 111: Me.Load += New System.EventHandler(Me.Page_Load)
Line 112:
Line 113: End Sub

I'm researching each of them to try to find a solution, but I thought I'd also post them here. So if I can get just a bit of further direction on how to solve these errors, it would be greatly appreciated. Thanks again for any help.

KWilliams
Reply With Quote
  #5 (permalink)  
Old October 13th, 2006, 05:08 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Here you go:

result = result.replace("xmlns:asp=\remove\", "")

and

AddHandler Me.Load, AddressOf Page_Load

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
Reply With Quote
  #6 (permalink)  
Old October 13th, 2006, 07:58 PM
Authorized User
 
Join Date: Feb 2004
Location: , , .
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

(via Instant VB)
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls

' add references for XSLT
Imports System.Xml
Imports System.Xml.Xsl
Imports System.Xml.XPath

' add references for Streams
Imports System.IO

Namespace CustomSurveys
    ''' <summary>
    ''' This is a custom survey page, where the questions
    ''' are created at runtime
    ''' </summary>
    Public Class WebForm1
        Inherits System.Web.UI.Page
        Protected Title As System.Web.UI.WebControls.TextBox
        Protected survey As System.Web.UI.WebControls.PlaceHolder
        Protected ThankYouLabel As System.Web.UI.WebControls.Literal

        Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
            If IsPostBack Then
                ProcessSurveyResults()
                survey.Visible = False
                ThankYouLabel.Visible = True
            Else
                survey.Visible = True
                ThankYouLabel.Visible = False
            End If
        End Sub

        Private Sub CreateSurvey()
            ' Load the data source
            Dim surveyDoc As XPathDocument = New XPathDocument(Server.MapPath("ExSurvey.xml"))

            ' Load the xslt to do the transformations
            Dim transform As XslTransform = New XslTransform()
            transform.Load(Server.MapPath("MakeControls.xslt") )

            ' Get the transformed result
            Dim sw As StringWriter = New StringWriter()
            transform.Transform(surveyDoc, Nothing, sw)
            Dim result As String = sw.ToString()

            ' remove the namespace attribute
            result = result.Replace("xmlns:asp=""remove""", "")

            ' parse the control(s) and add it to the page
            Dim ctrl As Control = Page.ParseControl(result)
            survey.Controls.Add(ctrl)
        End Sub

        Private Sub ProcessSurveyResults()
            ' Load the data source
            Dim surveyDoc As XPathDocument = New XPathDocument(Server.MapPath("ExSurvey.xml"))
            ' create an iterator
            Dim itr As XPathNodeIterator = surveyDoc.CreateNavigator().Select("//question")
            ' string builder for survey body
            Dim sb As System.Text.StringBuilder
            sb = New System.Text.StringBuilder()
            ' submission information
            sb.Append("Survey submitted on " & DateTime.Now & Environment.NewLine)
            ' foreach question
            Do While itr.MoveNext()
                ' get the control name
                Dim controlName As String = itr.Current.GetAttribute("name", "")
                ' append question information
                sb.Append(controlName)
                sb.Append(" : ")
                ' get the control
                Dim ctrl As Object = FindControl(controlName)
                ' append the correct filled out information
                If TypeOf ctrl Is TextBox Then
                    sb.Append((CType(ctrl, TextBox)).Text)
                End If
                If TypeOf ctrl Is RadioButtonList Then
                    ' the selected item might be null
                    If Not (CType(ctrl, RadioButtonList)).SelectedItem Is Nothing Then
                        sb.Append((CType(ctrl, RadioButtonList)).SelectedItem.Value)
                    End If
                End If
                sb.Append(Environment.NewLine)
            Loop
            Dim body As String = sb.ToString()

            ' send the results
            System.Web.Mail.SmtpMail.SmtpServer = "your.smtp.server"
            System.Web.Mail.SmtpMail.Send("survey@somewhere.co m", "your@address.com", "Survey result", body)
        End Sub

        #Region "Web Form Designer generated code"
        Overrides Protected Sub OnInit(ByVal e As EventArgs)
            '
            ' CODEGEN: This call is required by the ASP.NET Web Form Designer.
            '
            InitializeComponent()
            CreateSurvey()
            MyBase.OnInit(e)
        End Sub

        ''' <summary>
        ''' Required method for Designer support - do not modify
        ''' the contents of this method with the code editor.
        ''' </summary>
        Private Sub InitializeComponent()
' Me.Load += New System.EventHandler(Me.Page_Load);

        End Sub
        #End Region
    End Class
End Namespace


Reply With Quote
  #7 (permalink)  
Old October 16th, 2006, 08:36 AM
Banned
Points: 1,561, Level: 16
Points: 1,561, Level: 16 Points: 1,561, Level: 16 Points: 1,561, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2005
Location: , , .
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by dparsons
 Here you go:
result = result.replace("xmlns:asp=\remove\", "")
and
AddHandler Me.Load, AddressOf Page_Load
Thanks for the suggestions dparsons. I changed those two pieces of code as you suggested, but even though no error messages come up, the form fields are still not being displayed on the page even though they are in the code. I'm including the latest code that I'm using in hopes that my error(s) are noticable. Thanks for any help.

Code:
Namespace CustomSurveys

Public Class WebForm1
    Inherits System.Web.UI.Page
    Protected Title As System.Web.UI.WebControls.TextBox
    Protected survey As System.Web.UI.WebControls.PlaceHolder
    Protected ThankYouLabel As System.Web.UI.WebControls.Literal

    Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        If IsPostBack Then
            ProcessSurveyResults()
            survey.Visible = False
            ThankYouLabel.Visible = True
        Else
            survey.Visible = True
            ThankYouLabel.Visible = False
        End If
    End Sub

    Private Sub CreateSurvey()
        Dim surveyDoc As XPathDocument = New XPathDocument("survey.xml")
        Dim transform As XslTransform = New XslTransform
        transform.Load("survey.xsl")
        Dim sw As StringWriter = New StringWriter
        transform.Transform(surveyDoc, Nothing, sw)
        Dim result As String = sw.ToString
        'result = result.Replace("xmlns:asp=""remove""", "")
        result = result.Replace("xmlns:asp=\remove\", "")
        Dim ctrl As Control = Page.ParseControl(result)
        survey.Controls.Add(ctrl)
    End Sub

    Private Sub ProcessSurveyResults()
        Dim surveyDoc As XPathDocument = New XPathDocument("survey.xml")
        Dim itr As XPathNodeIterator = surveyDoc.CreateNavigator.Select("//question")
        Dim sb As System.Text.StringBuilder
        sb = New System.Text.StringBuilder
        sb.Append("Survey submitted on " + DateTime.Now + Environment.NewLine)
        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
        Dim body As String = sb.ToString
        System.Web.Mail.SmtpMail.SmtpServer = "your.smtp.server"
        System.Web.Mail.SmtpMail.Send("survey@somewhere.com", "your@address.com", "Survey result", body)
    End Sub

    Protected Overloads Overrides Sub OnInit(ByVal e As EventArgs)
        InitializeComponent()
        CreateSurvey()
        MyBase.OnInit(e)
    End Sub

    Private Sub InitializeComponent()
        'AddHandler Me.Load, AddressOf Me.Page_Load
        AddHandler Me.Load, AddressOf Page_Load
    End Sub
End Class
End Namespace
KWilliams
Reply With Quote
  #8 (permalink)  
Old October 16th, 2006, 08:58 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Well,
    The call AddHandler Me.Load, AddressOf Page_Load isn't truly needed as your page load should be

Page_Load(ByVal object as System.Object, ByVal e as System.EventArgs)Handles MyBase.Load

Remove the call from your Init. (This was an error on my part because I just translated directly from C# to the VB equiv which, while accurate, isn't how you should do things)

Also, result should be equiv to this:

result = result.Replace("xmlns:asp=""remove""", "")

again this was an oversight on my part since the xmlns actually contains " " you need the double "" "" to properly match them.

hth.

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
Reply With Quote
  #9 (permalink)  
Old October 16th, 2006, 09:27 AM
Banned
Points: 1,561, Level: 16
Points: 1,561, Level: 16 Points: 1,561, Level: 16 Points: 1,561, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2005
Location: , , .
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by dparsons
 Well,
    The call AddHandler Me.Load, AddressOf Page_Load isn't truly needed as your page load should be

Page_Load(ByVal object as System.Object, ByVal e as System.EventArgs)Handles MyBase.Load

Remove the call from your Init. (This was an error on my part because I just translated directly from C# to the VB equiv which, while accurate, isn't how you should do things)

Also, result should be equiv to this:

result = result.Replace("xmlns:asp=""remove""", "")

again this was an oversight on my part since the xmlns actually contains " " you need the double "" "" to properly match them.
hth.
Doing these revisions resulted in no error messages, but unfortunately had the same result. Another error message I'm getting involves the initial Namespace statement, and I think that this could be causing the problem. This is the error:
BC30618: 'Namespace' statements can occur only at file or namespace level.

I've tried placing this linked source code doc just above and just below the main page's source code, but I end up with the same error message. On both tries, I made sure to place this linked source code just below the imports and option statements, as stated here http://msdn2.microsoft.com/en-us/library/f8za39hx.aspx.

This is how I have the code structured in the main ASPX page:

<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" AspCompat="true" Debug="true" %>
<%@ import Namespace="System.Collections" %>
<%@ import Namespace="System.ComponentModel" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Drawing" %>
<%@ import Namespace="System.Web" %>
<%@ import Namespace="System.Web.SessionState" %>
<%@ import Namespace="System.Web.UI" %>
<%@ import Namespace="System.Web.UI.WebControls" %>
<%@ import Namespace="System.Web.UI.HtmlControls" %>

<%@ import Namespace="System.Xml" %>
<%@ import Namespace="System.Xml.Xsl" %>
<%@ import Namespace="System.Xml.XPath" %>

<%@ import Namespace="System.IO" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script language="vb" runat="server" src="/bgscripts/vb/survey.aspx.vb" />
<script runat="server">

    'Declare variables
    Dim page_title As String

    Sub Page_Load(sender As Object, e As EventArgs)
    '...a bunch of code...
    End Sub
</script>

KWilliams
Reply With Quote
  #10 (permalink)  
Old October 16th, 2006, 12:06 PM
Banned
Points: 1,561, Level: 16
Points: 1,561, Level: 16 Points: 1,561, Level: 16 Points: 1,561, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2005
Location: , , .
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, I've been working with this page all morning, and this is where I'm at:

I think that the problem lies in the fact that I have an already-existing XSLT transformation that occurs in the main index.aspx Page_Load event, like this:
Code:
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" AspCompat="true" Debug="true" %>
<%@ import Namespace="System.Collections" %>
<%@ import Namespace="System.ComponentModel" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Drawing" %>
<%@ import Namespace="System.Web" %>
<%@ import Namespace="System.Web.SessionState" %>
<%@ import Namespace="System.Web.UI" %>
<%@ import Namespace="System.Web.UI.WebControls" %>
<%@ import Namespace="System.Web.UI.HtmlControls" %>

<%@ import Namespace="System.Xml" %>
<%@ import Namespace="System.Xml.Xsl" %>
<%@ import Namespace="System.Xml.XPath" %>

<%@ import Namespace="System.IO" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    'Declare variables
    Dim page_id As String, page_path As String, xmlURL As String, xslURL As String

    Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

        'Pull page_qs querystring variable
        Dim page_qs As String = Request.QueryString("page")
        'Load XML file internal_links.xml w/page_qs variable selected and assign page properties
        Dim il_xmld As XmlDocument
        Dim il_nodelist As XmlNodeList
        Dim il_node As XmlNode
        'Create the XML Document
        il_xmld = New XmlDocument()
        'Load the Xml file
        il_xmld.Load("/docs/xml/internal_links.xml")
        'Get the list of name nodes
        il_nodelist = il_xmld.SelectNodes("/internal_links/page[@id = '" & page_qs & "']")
        'Loop through the nodes
        For Each il_node In il_nodelist

            'Get an Attribute Value
            Dim page_id = il_node.Attributes.GetNamedItem("id").Value

            'Pull XML nodes
            page_title = il_node.Item("title").InnerText

    'Assign page_path
    If page_id <> "" Then
        page_path = page_id
    End If

    'Declare dynamic file paths
    xmlURL = "docs/xml/" + page_path + ".xml"
    xslURL = "docs/xslt/" + page_path + ".xsl"

    'Assign dynamic url for this page
    xslTransform.DocumentSource = xmlURL
    xslTransform.TransformSource = xslURL

    'Assign additional page properties
        Dim PageTitle As New HtmlGenericControl
        Me.PageTitle.InnerText = page_title

</script>
<script language="vb" runat="server" src="/survey/bgscripts/vb/survey.aspx.vb" />
<html>
<head runat="server">
    <title id="PageTitle" runat="server"></title>
</head>
<body>
    <form runat="server">
        <div id="wrapper">

            <asp:Xml id="xslTransform" runat="server"></asp:Xml>
        </div>
    </form>
</body>
</html>
I think that instead of having an external script, I need to dynamically include parts of the code within the main index.aspx page.

From re-reading the article and looking at the code, what I think I need to do is to somehow link an external VB.NET script that contains the xmlns:asp="remove" code, IsPostBack code, ProcessSurveyResults code, and OnInit code from survey.aspx.vb within Page_Load event on index.aspx.

I've been shown a way to do this using using events, like this:
Code:
Dim con As Control, myPlaceHolder As Control
        'Make sure you are reading stuff from your querystring...
        Select Case (page_qs)
            Case "home"
                con = LoadControl("/bgscripts/ascx/home.ascx")
                Exit Sub
            Case "survey"
                con = LoadControl("/survey/bgscripts/ascx/survey.ascx")
                Exit Sub
            Case Else
                con = LoadControl("/bgscripts/ascx/home.ascx")
                Exit Sub
        End Select


...but I'm not sure if it will work for what I need. I'm going to give it a try, but any advice on this would be great. Thanks.

KWilliams
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
File Conversion in VB.net? yuvin Visual Studio 2005 1 February 5th, 2007 03:36 PM
Conversion from .Net 2003 to .Net 2005 using VB.Ne coleenh Visual Basic 2005 Basics 0 September 19th, 2006 02:48 PM
conversion of vb to C# code KamalRaturi ASP.NET 2.0 Professional 6 September 13th, 2006 04:35 AM
VB to C# conversion shazia1 VS.NET 2002/2003 3 June 29th, 2005 08:12 PM
vb6 to vb.net conversion question tomz VB.NET 2002/2003 Basics 2 January 28th, 2004 10:51 AM



All times are GMT -4. The time now is 08:22 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.