Create ASP.Net Page Programatically

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mythran

    #1

    Create ASP.Net Page Programatically

    I have 2 projects, a Web project and a Class Library project. In the class
    project, I have a class called Class1. Pseudo below:

    Class Class1
    ...
    Public Static Sub Generate()
    If True
    ' Create Page and display to user.
    End If
    End Sub
    End Class


    The ASPX page follows:

    Class MyASPXPage
    ...

    Public Sub Page_Load(...)
    MyClassProject. Class1.Generate ()
    End Sub
    End Class


    How can I make the Generate() method create a new aspx page with a web
    control (Button) that, when clicked, will execute the event handler stored
    in Class1? The new aspx page we want to be created does not exist on the
    web server. We want to create it ourselves and possibly store it as a
    resource in the Class Library project.

    Basically, we want to include this class in any of our WebUI projects and if
    certain criteria are met, this page would be loaded and prompt the user for
    input. We do not want to create a new web application out of it (which is
    what we are currently doing).

    Any and all help appreciated.

    Thanks,
    Mythran


  • Cor Ligthert

    #2
    Re: Create ASP.Net Page Programatically

    Mythran,

    There are 2 ways to use (create) ASPX pages scripting and with a DLL.
    I post this from the language.VB newsgroup where the DLL way is mostly used.
    In the ASPNET newsgroup you see often a lot of scripting solutions.

    The Scripting format is where is said in the header to use VB or C# script
    on the serverside and the DLL is where is told in the header use the class.

    In my opinion can you to get your solution very good use the scripting
    format.

    Have just a look at gotdotnet how to make a scripting page.

    That than dynamicly created page can you than in my idea place in the IIS
    directory as start of your goal.

    (Not that I tried this ever however this sound for me so obvious)



    I hope this helps?

    Cor



    Cor


    Comment

    • Cor Ligthert

      #3
      Re: Create ASP.Net Page Programatically

      Mytrhan,

      I am not interested what you exactly want to do, however for me your first
      question was "how do I create a page on the fly" and on that I gave an
      answer. I am not making an solution for you.

      However to be sure if it was working, did I make this sample accoording to
      my previous message, and it showed me a simple page made on the fly. This
      will surely not fullfil al your needs quick reading your second page,
      however is exact as my answer.

      ///Needs one button on a webpage and than paste in this code in the code
      part
      Private Sub Button1_Click(B yVal sender As System.Object, _
      ByVal e As System.EventArg s) Handles Button1.Click
      Dim str As String = "<%@ Page Language='VB' %><html><head> " & _
      "</head><body><cen ter>" & _
      "<form><p>< %If Session.Item("" MyValue"") = ""Mythran"" then " &
      vbCrLf & _
      "Dim I As Integer" & vbCrLf & "For I = 0 to 7 %>" & vbCrLf & _
      "<font size='<%=I%>'> Welcome to ASP.NET </font> <br>" & vbCrLf & _
      "<% Next" & vbCrLf & _
      "End if%>" & vbCrLf & _
      "</form></center></body></html>"
      Dim sw As New
      IO.StreamWriter ("C:\Inetpub\ww wroot\WebApplic ation1\mytest.a spx")
      sw.Write(str)
      sw.Close()
      Session.Item("M yValue") = "Mythran"
      Response.Redire ct("mytest.aspx ")
      End Sub
      ///

      However if this is not what you want, than I probably don't understand you.

      I hope this helps?

      Cor



      Comment

      • Mythran

        #4
        Re: Create ASP.Net Page Programatically


        "Cor Ligthert" <notmyfirstname @planet.nl> wrote in message
        news:%23cxDPN0I FHA.3928@TK2MSF TNGP09.phx.gbl. ..[color=blue]
        > Mytrhan,
        >
        > I am not interested what you exactly want to do, however for me your first
        > question was "how do I create a page on the fly" and on that I gave an
        > answer. I am not making an solution for you.
        >
        > However to be sure if it was working, did I make this sample accoording to
        > my previous message, and it showed me a simple page made on the fly. This
        > will surely not fullfil al your needs quick reading your second page,
        > however is exact as my answer.
        >
        > ///Needs one button on a webpage and than paste in this code in the code
        > part
        > Private Sub Button1_Click(B yVal sender As System.Object, _
        > ByVal e As System.EventArg s) Handles Button1.Click
        > Dim str As String = "<%@ Page Language='VB' %><html><head> " & _
        > "</head><body><cen ter>" & _
        > "<form><p>< %If Session.Item("" MyValue"") = ""Mythran"" then " &
        > vbCrLf & _
        > "Dim I As Integer" & vbCrLf & "For I = 0 to 7 %>" & vbCrLf & _
        > "<font size='<%=I%>'> Welcome to ASP.NET </font> <br>" & vbCrLf & _
        > "<% Next" & vbCrLf & _
        > "End if%>" & vbCrLf & _
        > "</form></center></body></html>"
        > Dim sw As New
        > IO.StreamWriter ("C:\Inetpub\ww wroot\WebApplic ation1\mytest.a spx")
        > sw.Write(str)
        > sw.Close()
        > Session.Item("M yValue") = "Mythran"
        > Response.Redire ct("mytest.aspx ")
        > End Sub
        > ///
        >
        > However if this is not what you want, than I probably don't understand
        > you.
        >
        > I hope this helps?
        >
        > Cor
        >
        >[/color]

        Ok, I see what you are talking about here....now I'm understanding where we
        are getting a little mis-understood. You are writing out an aspx page on
        the file to the server's disk. What I was wondering was if there was a way
        to create the page and send it to the client w/o writing it to the server's
        disk first. From there, it would post back and fire events in the dll that
        created the page...

        See where I'm heading now?

        Thanks :)

        Mythran


        Comment

        • Cor Ligthert

          #5
          Re: Create ASP.Net Page Programatically

          Mythran,
          [color=blue]
          >What I was wondering was if there was a way to create the page and send it
          >to the client w/o writing it to the server's disk first. From there, it
          >would post back and fire events in the dll that created the page...[/color]

          That is not any problem, you can redirect that page as a string (Not in the
          way I showed you however in clear HTML). However, than you are loosing all
          the functionality from the server. That was exactly why I wrote as extra too
          the dotnet page sample that session functionality in it. Please try to
          understand the answers first before you start typing.

          However I don't see the problem. This is a sample, probably I would in a
          real situation give it as page name a Guid and deleted it as soon as it was
          redirected. However that I did not try, that kind of functionality you would
          have to do yourself in my opinion or ask for it. As I said, I am not making
          your solution, only giving some hints. And in this case an even very
          extended hint.

          I hope this helps?

          Cor


          Comment

          • Mythran

            #6
            Re: Create ASP.Net Page Programatically


            "Cor Ligthert" <notmyfirstname @planet.nl> wrote in message
            news:uvRZOU7IFH A.2640@TK2MSFTN GP09.phx.gbl...[color=blue]
            > Mythran,
            >[color=green]
            >>What I was wondering was if there was a way to create the page and send it
            >>to the client w/o writing it to the server's disk first. From there, it
            >>would post back and fire events in the dll that created the page...[/color]
            >
            > That is not any problem, you can redirect that page as a string (Not in
            > the way I showed you however in clear HTML). However, than you are loosing
            > all the functionality from the server. That was exactly why I wrote as
            > extra too the dotnet page sample that session functionality in it. Please
            > try to understand the answers first before you start typing.
            >
            > However I don't see the problem. This is a sample, probably I would in a
            > real situation give it as page name a Guid and deleted it as soon as it
            > was redirected. However that I did not try, that kind of functionality you
            > would have to do yourself in my opinion or ask for it. As I said, I am not
            > making your solution, only giving some hints. And in this case an even
            > very extended hint.
            >
            > I hope this helps?
            >
            > Cor
            >
            >[/color]

            Thanks for the help.

            Mythran


            Comment

            • Vinay

              #7
              RE: Create ASP.Net Page Programatically

              Hi ,
              Please tell me whether your probelm is solved of dynamic creation of aspx page on fly and save it to the disk.

              If yes, then please help me out with code snippit.



              From http://www.developmentnow.com/g/8_20...amatically.htm

              Posted via DevelopmentNow. com Groups
              DevelopmentNow is an award-winning creative software development agency integrating mobile, web, hardware, mixed reality, and emerging technology.

              Comment

              Working...