Loading html page from a template on the computer - c#

I am working with a C# on visual studios.
What I would like to know is if it is possible to have a html template loaded from a directory on my computer. Then every time I load up my code it will load up the .html template automatically.

Yes there is a way, not suggested but exist. You can use this code to include the file, inside your asp.net page.
<!--#include file="template.htm"-->
What is dose is that is load this htm file and show it on the place that you have place this declaration. Also you must know that this file can not contain anything dynamically. This is a command code that comes from the old asp script code, and still work on asp.net
So I can not call it as template. If you wish to make something like a real template you must use a master page. Using a master page is far better, and you just copy paste your htm code inside the master page and there you have it.
relative: http://triaslama.wordpress.com/2008/11/19/how-to-include-file-in-aspnet-pages/

Related

In VS 2019 - How to regenerate code-behind and designer files from an existing aspx page

I imported in my project Web c# an aspx page, for example, mypage.aspx, with HTML code. This page is very simple.
All I want is to generate the 2 files (in IDE) aspx.cs and designer.cs (mypage.aspx.cs and mypage.aspx.designer.cs).
I tried "Convert to web project" functionality but it does not work.
Any idea, please?
Of course, I read several solutions on this site but none worked (with vs 2019).
If there is no actual code in the original code-behind file then it's pretty easy to do. Create a new page of the same name. Then just copy and paste the markup from the original, taking care to leave the newly-created page directive as is.
If there was logic in your original code-behind then you're out of luck. You might try decompiling the original DLL and try to re-create the original code that way.

Editing HTML via asp.net

So I am using asp.net to make a site, and I came across a bit of a problem. I need to edit the html from an .aspx.cs file, and while this normally isn't a problem, the html file is located in a templates folder elsewhere in the project. I have tried using javascript, but I kept getting errors saying "cannot setAttribute/change innerHTML of type null.
Would it be better to continue trying to fix this with javascript, or does asp.net have something for this?
ALSO NOTE: the html is in an html file, not a .aspx file, so asp.net controls (such as runat="server") don't work.
EDIT: What I am trying to do is hide a div that holds a navigation bar for admins if the current user is not an admin.
For javascript fixes, I have tried Page.RegisterStartUpScript and Response.Write (called from the .aspx.cs file), but both give me the error described above. I can't (as far as I know) have a javascript file just hide the div without somehow being called or originated by the c#, as I need to find out whether or not they are an admin
What you need to do is convert the HTML document to an .aspx file and include it (Ref. http://www.mikesdotnetting.com/Article/144/Classic-ASP-Include-Files-in-ASP.NET) in the other documents where it is to be used. Then, you can reference the control in your code behind, using whatever methods are available to you for determining whether or not a user is logged in. For example:
if (Security.IsLoggedIn())
{
myIncludeFile.Visible = true;
}
else
{
myIncludeFile.Visible = false;
}
Does that make sense to you?

GridView to Excel ASPX in SharePoint

I have an ASPX file which I am running in SharePoint that has a GridView which I am attempting to export into an excel spreadsheet. I know the code I have for the export is correct; however, I am getting this error:
RegisterForEventValidation can only be called during Render();
I have done some research and have found a solution, which might work with normal ASPX pages created in VS with a CS code behind class, which is setting the EnableEventValidation to false, and I am getting a Parser error when I attempt to use this solution on my ASPX page.
<%# Page Language="C#" AutoEventWireup="true" EnableEventValidation = "false"%>
Is there any other way to allow this, or any other workaround to my problem using just the ASPX page without the code behind? All of my C# code is within the head and has to be in order for me to run it in my SharePoint environment. 12 hive storage of the CS class is not an option for me. Also, I am not wanting to change anything in my web.config folder if possible.
Thanks
Try creating it as a Web Part - this is the more common approach for this type of scenario in SharePoint.
In SharePoint, all customized pages are run through the Safe Mode Parser which prohibits inline code. Also, this parser does not allow adding controls to pages which have not been marked as "safe".
To get around your issue, you might want to look at "Application Pages" which are added to the \LAYOUTS directory. They reference the master page and can have inline code, but they can't be customized. They are compiled into a single assembly DLL:
Creating an Application Page in Windows SharePoint Services 3.0

How create dynamic view page and css file in mvc3

I am working on small project Fast Food Ads in Mvc3 using c# .I want to create page where user can set the layout of page like header , footer and menu bar etc. manually so I think this page its HTML and Css file should be create dynamically. page name and css file will be unique for every user how can i do this?
I don't want to use any CMS...
In principal you can use the Razor engine in MVC3 to process any of your files. You can already do that for your HTML files.
If you want to use Razor to dynamically process (or even create, on the fly) your CSS, have a look at RazorJs. RazorJs allows Razor to pre-process Javascript files before they are included in a view. I have not looked at it's source code, but I imagine it should be straightforward to adapt it to pre-process CSS as well.

Best way to copy a web form page within a project?

So let's say you wanted to make a copy of a Web Form page within a .Net Project.
Is there an easier way than:
Copy Source Page
Page Source Page within project to get new page
Exclude Source Page
Rename code behind class for new page
Add Source Page Back
Sometimes I miss something obvious is there a better way to do this? I know the next question would be "Why are you copying code within a project instead for reusing it?" Let's just say that's a secret;).
I do this:
Select the original ASPX file in solution explorer
Ctrl+C followed by Ctrl+V (quick copy paste)
Rename new ASPX file (let's say NewFile.aspx)
Rename code-behind class name to NewFile
Rename Inherits attribute of Page directive within HTML to end with 'NewFile'
(Optional) If you moved the page into a different folder, you'll need to update the Namespace references in the HTML's Page directive as well as in the code-behind.
Create new page via "Add New Item"
Copy original markup (minus Page declaration) and paste into new page
Copy code from original code-behind and paste into the new code-behind
Can you make that form a User Control, and then insert it as needed? Then you can save yourself the trouble of editing every instance of it that you copy.

Categories

Resources