How to create ASPX Page Dynamically - asp.net

i have two controls on asp.net page , textbox and button and i want to write new page into textbox then when i hit the button i want to create new asp.net web page with textbox text. what do you want me to prefer to do this? is there any step by step tutorial or any code you have done before? thanks for asnwers.
ok more detail about what i want.
textbox control text is "contact" and i click my button control. button take textbox text "contact" and create new web form page which name is "contact.aspx and its code page contact.cs" . thats it. just create new web form page under root directory with button click.
maybe there is a single code line like
Page pg =new Page();
pg.create();

You can use File.WriteAllText to write the contents of the textbox to any location that the application pool user has permissions to write to.
From your edit it appears that you are looking for a CMS/wiki kind of functionality. There is nothing like that built into the .NET framework.
I suggest you look for wiki software.

No need to worry about big codes etc
You can create it with 2 simple steps explained in my blog
Create one empty page then copy it using Files concept. Save it as what ever name you want.
Try to change the content inside newly created page to Run smoothly
Please visit my blog for example solution
Click here for Solution Post

You can use the Page.ParseControl method.
Beware, it does not support everything you can do with a real ASPX or ASHX file, but it works for simple things. An example is available here: Using Page.ParseControl to add new control from Control Tag

There is very simple way to do that. It is working on principe to Copy one your Page, you should put Page with controls that you want to use on your other pages. So first you need using System.IO; then you need this code
protected void Button1_Click(object sender, EventArgs e)
{
try
{
File.Copy(Server.MapPath("") + "\\Submit.aspx", (Server.MapPath("") + "\\" + TextBox1.Text + ".aspx"));
File.Copy(Server.MapPath("") + "\\Submit.aspx.cs", (Server.MapPath("")+ "\\" + TextBox1.Text + ".aspx.cs"));
Response.Redirect(TextBox1.Text + ".aspx");
}
catch
{
Response.Write("<script>window.alert('This page is taken. Please change name!')</script>");
}
}
As you can see, The page you are coping is called Submit, and new Name of your Page is called like textbox1.text.
I hope that this helped you and anyone else.

enter link description here
Before some time I saw a logical question in a web site in this a person give the problem as like this
“I have one page called First.aspx in my web application, in this page; I have a simple asp.net button control. And I want is, on the click event of that button control, create (render) a new dynamic "page" that can be opened in a new windows or tab”
.
Here we give An Example here to creating a new .aspx page at run time. We also give the option to give page name. The user can give as he/she like. Like Google blogging we make new page at runtime.The new page is not in the website, this page create needs to be created at runtime and needs to be dynamic.

Related

SSRS - Link not clickable in .net Report Application

I have a report that specifies a 'Go to URL' action for a textbox. The URL I am using is simply a field from the dataset, so the expression for the URL is something like "=Fields!URLLinkText.Value". When I deploy the report to SSRS Report Manager, the link works fine. It is clickable and opens the URL. However, when I link to the report from the custom asp.Net Reporting Application, the link is not clickable. The cursor of the mouse does not even change when I hover over the link. It seems like the hyperlink/Go To property of the textbox is completely removed. At first, I thought that this had to be an issue with the configuration of the reporting app, which was disabling external hyperlinks. However, I created another report with just one textbox with a Go To Action to go to www.CNN.com and it worked on both the Report Manager and the Report Application...
Any suggestions?
I was just posting about a possibly related issue. It does not involve any custom reporting app though. http://weblogs.asp.net/mnissen/archive/2009/03/26/reporting-services-does-not-display-hyperlink-for-placeholder-with-go-to-url-action.aspx
A few different options you can try: wrap the link in javascript, try "servername:port" instead of the site name if its internal, or try reversing the slashes like http backslash backslash...
You will need to handle the Hyperlink clicked event for your reportviewer control:
Assign the handler in your reportviewer constructor
YourReportViewerControl.Hyperlink += new HyperlinkEventHandler(YourReportViewerControl_Hyperlink);
void YourReportViewerControl_Hyperlink(object sender, HyperlinkEventArgs e)
{
e.Cancel = true;
System.Diagnostics.Process.Start(e.Hyperlink);
}

Inherited an ASP.NET app & have some simple questions

I'm a PHP/Rails developer and have inherited an ASP.NET application (and its maintenance). So I have a few simple questions.
1.) What's the makeup of a typical rendered(compiled?) HTML page in ASP.NET. That is, when a request is made what happens from the initial request to the time the HTML is displayed in the browser? I'm assuming some templates are combined and finally rendered but I'd like a more in-depth answer.
2.) I've been asked to remove a link from a Login form which is an aspx page. Looking at the aspx page itself it has an inherit statement, a link to the codebehind file, and links some other resources. Where do I actually remove the link from the Login page/template at? I've so far been unable to find exactly where the link is written so that I can remove it or comment it out.
Thank you!
That is, when a request is made what happens from the initial request
to the time the HTML is displayed in the browser?
I'd start learning about the ASP.Net Page Life Cycle.
I've so far been unable to find exactly where the link is written so
that I can remove it or comment it out.
I wouldn't do anything until you have at least a decent grasp of how ASP.Net works. It would be good to run through a few tutorials. ASP.Net has a nice Get Started section.
What's the makeup of a typical rendered(compiled?)
To give you a very simple instructions (trying) to help you fast understand it:
There is a page with the aspx tags, the asp.net is running the code behind and fill this tags with data.
After the filling with data on code behind, the asp.net is "running" the full page and if you have <% %> inside the aspx page, addition code runs that exist inside that.
This is a simple example:
public partial class Dokimes_StackOverFlow_Diafora : System.Web.UI.Page
{
public string cRenderMeAlso = "test";
protected void Page_Load(object sender, EventArgs e)
{
txtText.Text = "One Test";
}
}
<form id="form1" runat="server">
This will fill when the page is prepared
<asp:Literal runat="server" ID="txtText"></asp:Literal>
<br />
This will be render as the page reads out to send it to the browser
as php do
<%=cRenderMeAlso%>
</form>
Now in the place of the Literal control, you can have a full custom render control, that maybe a new complex part of a page with his elements and render.
Each page, master page, user control have a cycle of calls to help first pass all from Init() and prepare them, then pass all from Load(), and the other stage, giving the ability to initialize them in parallel - together.
Now, on PostBack the page have been keep some information's on ViewState that are posted together with the rest post data, and the Code behind use all that data to fill the controls. Also its fires on code behind any click event you have initialize on buttons and you can run some code there to do your work.
I've been asked to remove a link from a Login form
if you can not find that link is maybe on the standard login form that asp.net gives, the solution to that is to render the full template of the form, and remove it from there - but because there is the case to break the Login form, is better to not remove it and just hide it - because if you remove it and the code behind ask for it, it will throw an error - I mean for the standard asp.net forms login code that is part of the asp.net.
So if this is the case, render the login control as template (from design mode, do that on properties), see the link you search and ether make on code behind Link.Visible = false, ether remove it and delete on code behind all the reference on it.

New .aspx page in Visual Studio Web Application crashes page

i'm having a WebPart for displaying information about employees and i want to display only a view information about the persons. The rest should be available after clicken on a "more" link. I tried to get that with opening a "popup"window.
But i don't get that to work right. So i tried using a new page. Hence i added a new aspx page to my project in visual studio
and added a link to that page like that:
LinkButton link = new LinkButton(); link.Width = Unit.Pixel(20);
link.Text = "more";
After building the project i tested it in my webpart page and get an error
"An unexpected error occured".
It took me a lot to get the webpart work properly again.
Has anybody an idea what i'm doing wrong. (i also tried to catch an exception without success)
I also tried to add an click event to that "more" link. but then, when i hover above that link with the mouse i see
"javascript:__doPostBack('ctl00$m$g_84d91faf_d0a8_4587_bb7c_712030d2c4ea$ctl00$ctl18','')"
i tried with link.OnClientClick and link.OnClick, nothing works.
I really need that function for that page.
I would highly appreciate it if you can give me a code snippet of a solution.
Thanks in advance
You should use PostBackUrl property of linkbutton Or on button click event you can call Response.Redirect

asp.net make button show different view of MultiView AND download a file

I have a page on my site on which users have to fill out details before they can download a document. The user details section is on the first view in a MultiView control.
After filling out their details I'd like the user to click a button which will show them a file download prompt (I've done this successfully with an ashx handler) then redirect them to the second view page of the MultiView which will say "thank you for downloading" or something like that.
I've tried the usual Response.Redirect("~/DownloadHandler.ashx"); within the button click event handler, but obviously this prevents the page completing the postback and showing the last page of the MultiView.
Is there a way around this, or should I just change my UI to accommodate this?
EDIT:
I've concluded that it's better to just provide a hyperlink to the document (on my confirmation page, and change the wording accordingly) as this provides a consistent user experience independent of the browser they're using.
Go ahead and take them to the second view of the MultiView. Add a javascript method that will download the document, and trigger it from your codebehind.1 E.g.,
In your page:
<script>
function downloadFile(url) {
window.location = url;
//you could also try window.open(url, 'Download')
}
</script>
In your code behind:
script = string.Format("downloadFile('{0}');", "DownloadHandler.ashx");
Page.ClientScriptManager.RegisterStartupScript(typeof(Page), "download", script, true);
You could also add a delay (using setTimeout) before the file is downloaded.
More info:
Initiating a file download that works well, even in IE?

Display a Photo Gallery using Asp.Net and SQL

I have recently added photos to my SQL database and have displayed them on an *.aspx page using Asp:Image. The ImageUrl for this control stored in a separate *.aspx page. It works great for profile pictures.
I have a new issue at hand. I need each user to be able to have their own photo gallery page. I want the photos to be stored in the sql database. Storing the photos is not difficult. The issue is displaying the photos. I want the photos to be stored in a thumbnail grid fashion, when the user clicks on the photo, it should bring up the photo on a separate page.
What is the best way to do this. Obviously it is not to use Asp:Image. I am curious if I should use a Gridview. If so, how do I do that and should their be a thumbnail size stored in the database for this?
Once the picture is click on how does the other page look so that it displays the correct image. I would think it is not correct to send the photoId through the url.
Below is code from the page I use to display profile pictures.
protected void Page_Load(object sender, EventArgs e)
{
string sql = "SELECT [ProfileImage] FROM [UserProfile] WHERE [UserId] = '" + User.Identity.Name.ToString() + "'";
string strCon = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["SocialSiteConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(strCon);
SqlCommand comm = new SqlCommand(sql, conn);
conn.Open();
Response.ContentType = "image/jpeg";
Response.BinaryWrite((byte[])comm.ExecuteScalar());
conn.Close();
}
"The ImageUrl for this control stored in a separate *.aspx page. It works great for profile pictures." - rather than an .aspx page, why not a generic ASP.NET handler (.ashx) instead? They are a little more lightweight than an .aspx. Just search "ASP.NET Generic Handler" and you'll find a number of samples. It's basically the code you have now behind your .aspx page, but without all the page initialization/rendering overhead.
"I want the photos to be stored in a thumbnail grid fashion, when the user clicks on the photo, it should bring up the photo on a separate page." - I would think any ASP.NET repeatable control that supports templating of the item element (such as DataGrid, GridView, Repeater, ListView in ASP.NET 3.5, etc) should do the trick for you here. Just set the image or asp:Image height and width as appropriate for your thumbnails. Wrap which ever tag you use in an HTML anchor with an href to your page that displays the image at "full size".
Let's deconstruct your question:
Should their be a thumbnail size stored in the database for this?
Yes. Generate the thumbnail the first time the photo thumbnail is requested and cache it in the DB for future access
Obviously it is not to use Asp:Image
There is no problem using Asp:Image. You will be fine with it
I am curious if I should use a Gridview
Maybe a Repeater is better, but you will be fine with a gridview if you are familiar with it
I would think it is not correct to send the photoId through the url.
It is correct, but you should check if the photo belongs to the current user (don't trust the URL.
Generating the thumbnail
You will learn that the resized image generated by .net are poor quality. You should use some GDI kung-fu to get quality pictures.
Refer to this post http://codebetter.com/blogs/brendan.tompkins/archive/2004/01/26/use-gdi-to-save-crystal-clear-gif-images-with-net.aspx to learn more
You can try this
or this. They should get you started on the grid side. Correct on sending the imageid from the url. Look at a session variable or hidden control and post the form and read in on the next page.
I would look at a gridview and use a template column in combination with the html image tag in the gridview . Create the thumbnail as they upload it and store them both in the database. From there, you can easily retrieve it. This way displaying the image is quicker and there is no thumbnail conversions necessary at display time.
Well you would have a page for just displaying a photo (like you have above) but your criteria would be different. You would not use WHERE [UserId] = '" + User.Identity.Name but would have to send a query string id for the id of the photo in the database.
Then when you want the pic in your aspx page you would have to put an image html tag <image src="photo.aspx?id=2" />
How you put the html image tags on the page is not important.
The RbmBinaryImage control will help you display images directly from your database. You could bind the Image field directly to the ImageContent property, also you could specify whether you want the display to be as a thumbnail or not and provide the thumbnail size.
to get it go to http://www.ramymostafa.com/?p=187
If you don't want to reinvent the wheel you can integrate an open source gallery like Gallery Server Pro (www.galleryserverpro.com) into your site. It is written in C# / ASP.NET and does all the things you want.
Roger
[disclaimer] I am the Creator and Lead Developer of Gallery Server Pro [/disclaimer]

Resources