Create ASP.Net Page Programatically

Discussion in 'ASP .Net Web Controls' started by Mythran, Mar 4, 2005.

  1. Mythran

    Mythran Guest

    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
     
    Mythran, Mar 4, 2005
    #1
    1. Advertising

  2. Mythran

    Cor Ligthert Guest

    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)

    http://samples.gotdotnet.com/quickstart/

    I hope this helps?

    Cor



    Cor
     
    Cor Ligthert, Mar 4, 2005
    #2
    1. Advertising

  3. Mythran

    Mythran Guest

    "Cor Ligthert" <> wrote in message
    news:...
    > 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)
    >
    > http://samples.gotdotnet.com/quickstart/
    >
    > I hope this helps?
    >
    > Cor
    >
    >
    >
    > Cor
    >


    Well, Cor, what we are trying to do is create a security system. We have
    done quite a bit with security for asp.net and are trying this as a "try
    only" test. What we want to do is create a .Net assembly which will be our
    security library. This library will then contain a method, such as
    Generate(). When the method is called, it will check all sorts of criteria,
    just to make sure the user isn't already logged in. If they are not logged
    in to this application, or another application, then we want the dll to show
    a page. The page, though, should be output from the dll. The more I write
    this, the more I think I can just spit out some generic html and then catch
    the POST vars that are sent back from the security screen. Anywho, what I
    was asking earlier was if there was a way to generate the ASPX page on the
    fly. Or maybe store it into the assembly then spit it out when required. I
    don't see how it could work, but I bet there is probably a way.

    Not sure what I'm saying is clear enough for everyone to understand what we
    are trying to do...

    Thanks in advance and for help already given,

    Mythran
     
    Mythran, Mar 7, 2005
    #3
  4. Mythran

    Cor Ligthert Guest

    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(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click
    Dim str As String = "<%@ Page Language='VB' %><html><head>" & _
    "</head><body><center>" & _
    "<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\wwwroot\WebApplication1\mytest.aspx")
    sw.Write(str)
    sw.Close()
    Session.Item("MyValue") = "Mythran"
    Response.Redirect("mytest.aspx")
    End Sub
    ///

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

    I hope this helps?

    Cor
     
    Cor Ligthert, Mar 7, 2005
    #4
  5. Mythran

    Mythran Guest

    "Cor Ligthert" <> wrote in message
    news:%...
    > 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(ByVal sender As System.Object, _
    > ByVal e As System.EventArgs) Handles Button1.Click
    > Dim str As String = "<%@ Page Language='VB' %><html><head>" & _
    > "</head><body><center>" & _
    > "<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\wwwroot\WebApplication1\mytest.aspx")
    > sw.Write(str)
    > sw.Close()
    > Session.Item("MyValue") = "Mythran"
    > Response.Redirect("mytest.aspx")
    > End Sub
    > ///
    >
    > However if this is not what you want, than I probably don't understand
    > you.
    >
    > I hope this helps?
    >
    > Cor
    >
    >


    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
     
    Mythran, Mar 7, 2005
    #5
  6. Mythran

    Cor Ligthert Guest

    Mythran,

    >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...


    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
     
    Cor Ligthert, Mar 8, 2005
    #6
  7. Mythran

    Mythran Guest

    "Cor Ligthert" <> wrote in message
    news:...
    > Mythran,
    >
    >>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...

    >
    > 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
    >
    >


    Thanks for the help.

    Mythran
     
    Mythran, Mar 9, 2005
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Cowboy \(Gregory A. Beamer\)

    Re: programatically create controls on the fly

    Cowboy \(Gregory A. Beamer\), Jul 31, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    433
    Cowboy \(Gregory A. Beamer\)
    Jul 31, 2003
  2. =?Utf-8?B?YWxleA==?=

    create html and .net controls programatically

    =?Utf-8?B?YWxleA==?=, Jun 10, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    567
    bruce barker
    Jun 10, 2004
  3. Craig Wilson
    Replies:
    3
    Views:
    4,874
    clintonG
    Nov 12, 2004
  4. Mythran

    Create ASP.Net Page Programatically

    Mythran, Mar 4, 2005, in forum: ASP .Net
    Replies:
    7
    Views:
    1,345
    Vinay
    Apr 20, 2007
  5. Mark B

    Programatically create aspx page?

    Mark B, Mar 15, 2010, in forum: ASP .Net
    Replies:
    13
    Views:
    2,576
    Andrew Morton
    Mar 19, 2010
Loading...

Share This Page