473,378 Members | 1,400 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,378 software developers and data experts.

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
Nov 21 '05 #1
6 1101
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
Nov 21 '05 #2

"Cor Ligthert" <no************@planet.nl> wrote in message
news:uD**************@tk2msftngp13.phx.gbl...
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
Nov 21 '05 #3
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\WebApplication 1\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

Nov 21 '05 #4

"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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\WebApplication 1\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
Nov 21 '05 #5
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
Nov 21 '05 #6

"Cor Ligthert" <no************@planet.nl> wrote in message
news:uv**************@TK2MSFTNGP09.phx.gbl...
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
Nov 21 '05 #7

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

Similar topics

7
by: pintihar | last post by:
Hi, As a follow on from an earlier post I have another question about xslt. Is it possible to create the stylsheet programatically? Is this sensible? In the first phase I needed to map element...
2
by: Dave Bootsma | last post by:
Is it possible to programatically save a certain image from a certain web page? I want to automatically get a specific graphic from a specific web page programatically so I can automate the...
3
by: CodeRazor | last post by:
Hi, I am trying to dynamically create linkbuttons. They need an event handler, so i can respond to the user's click. I try to add the eventhandler on the fly, but when i click on the link, the...
0
by: spamfurnace | last post by:
Hi there on this rainy old day, I have some users logging into an asp.net website. The server the site sits on allows users to webmail through a common service/component called Horde. In order...
1
by: Fredrik | last post by:
How to I solve the following requirement on my application? On a generated aspx page, there should be a button "Create Document". When the user clicks this button, the application creates (on...
6
by: Mythran | last post by:
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 '...
0
by: jason | last post by:
I googled a lot, couldn't find a good solution. Any help is greatly appreciated. What I want to do is: Given a web page in a running IE browser , i want to save an image in this web page to...
1
by: Allan Ebdrup | last post by:
I get the error: "Cannot create an object of type 'CustomWizard' from its string representation 'CustomWizard1' for the CustomWizard Property." when I view my custom server web control in...
7
by: The Mad Ape | last post by:
Hi I have code to programatically create a label. It works but when I try to call a sub to create a tooltip it does not work. I do not get an error so have no idea what it wrong. Please review...
11
by: Mark B | last post by:
I want to display a pre-designed graphical 'performance badge' on certain webpages (round, about 2cm diameter) next to a salesperson's details. I have a function,...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.