Import HTML page in .NET - asp.net

The following code imports an HTML page (which simply holds one table) into my .ASP page. This works great, but I now am converting into .NET and am having obstacles.
<% Response.Write(getFilesContent("table.htm")) %>
This code does not work in .NET, and I read that this method is not recommended or widely used? Are there any thoughts, advice, or solutions about this?
I simply want to import this HTML page to read in a content box within my .NET page. In essence, the .NET page is hosting the HTML table.
Any help would be greatly appreciated.
Thank you in advance for your time and help.

To get you started, take a look at the System.Net.WebClient class http://msdn.microsoft.com/en-us/library/system.net.webclient%28v=vs.80%29.aspx
In particular, the "DownloadXXX" methods.

You could put the table in an asp.net user control
A asp.net custom user control can act like an include that encapsulates asp.net
markup.
here is a tutorial:
http://ondotnet.com/pub/a/dotnet/excerpt/progaspdotnet_14/index1.html
After you create the control add a reference
<%#Register tagprefix="uc" Tagname="html" src="custom_html.ascx" %>
then just a the control markup (in this case <uc:html runat="server"/>)
It would be cool the create a control the reads an html file by adding a src property

Try this:
<% Response.Write(New StreamReader(Server.MapPath("~/table.htm")).ReadToEnd()) %>

Related

How to pass an object from .cs to .aspx

I am a asp .net beginner. I want to use some objects created at Site.Master.cs in Site.Master. Is there an easy way to do it?
I know how to do it in MVC(by using view(the object)). But how can i do it in normal ASP .net web application?
I don't understand what exactly you want to do.
If you want to insert some string into tag's title you can insert the following thing in SiteMaster.master file:
<img src="<%= Page.ResolveUrl("~/") %>images/logo.png">
instead of:
<img src="images/logo.png">
In the first case there will be calculated the path from the root of your application. In the second case there will be relative link. This is because server will CALCULATE the value of Page.ResolveUrl("~") function and will WRITE it in src tag.
You can do the same thing with any other methods, classes if you defined them properly. But I wouldn't recommend you to implement complicated logic in .aspx files (or .master files). Because you can end up with many difficulties with testing and styling such application.
There are other server tags:
<% %> - an embedded code block is server code that executes during the page's render phase. The code in the block can execute programming statements and call functions in the current page class. Description and examples
<%= %> - most useful for displaying single pieces of information. Description and examples
<%# %> - data binding expression syntax. Description and examples
<%$ %> - ASP.NET Expression. Description and examples
<%# %> - Directive Syntax. Description and examples
<%-- --%> - Server-Side Comments. Description and examples
<%: %> like <%= %> - But HtmlEncodes the output (new with Asp.Net 4). Description and examples
Another way: you can use JSON to send some data to the client and then process it with javascript. Take a look at this project.
If the #Page directive in your .aspx file has Inherits="XYZ" where XYZ is the class declared in your .cs file, you can simply add a protected field to your class and assign a value to it. You'll be able to access it in the .aspx file just by using its name.
You can also use HttpContext.Items property to keep objects during a single request:
HttpContext.Current.Items["SavedItem"] = "hello world";
And use it in page:
<%= ((string)Context.Items["SavedItem"]) %>
Any public or protected property or method in Site.Master.cs will be accessible from Site.Master.
but how to invoke c# code in aspx ?
There are several ways, including the <%= %> construction, and databinding syntax.
It would help if you explained what you're trying to achieve.

what is the meaning of this?

I know that this will sound stupid to some of you, but when an ASPX page has something like this:
<%# Page Title="[$TITLES_listevents{uneditable}]" Language="C#" MasterPageFile="~/sitebase/templates/page.master" AutoEventWireup="true" CodeBehind="list.aspx.cs" Inherits="list" %>`
or something like:
<div id="panelGroupEventPackageOnlyDescription" runat="server" visible="<%# ShowGroupEventPackageOnly %>">
[$ITEMLIST_groupeventpackageonly]
</div>
what does it mean?
Regards
I'm assuming that your query is for the bits that look like this: Title="[$TITLES_listevents{uneditable}]"
It doesn't look like asp.net to me. It could be that the page was generated by a templating tool that left some rubbish behind, is it in source control, can you ask whoever created the page?
Hey All,
apparently it means that It will use site text to set the title, this is done when there is an xml file that produces site data and you need some of those data to be published dynamically to you front end website. this is the results of custom controls being used on things like label, dropdownbox etc...
this is one of the legacy piece of software where the one who wrote the code is gone AWOL with little doc, only happens when you are emerging from recession lol.....

BeginForm is not a member of 'Html' and Encode is not a member of HTML

I'm working on this big project in MVC ASP.NET w\ VB.NET
One of my views is getting me headaches since a few and i'm not sure what's up.
I've used the Begin.Form and Html.Encode methods alot in my other views and i never had any problems. Now this new Create.aspx view for one of my object called Automation is giving me multiple build errors such as those cited in the title plus
Error 184 'Context' is not a member of
'ASP.views_automatisation_create_aspx'.
BeginForm is not a member of 'Html'
Encode is not a member of HTML
My header is as follow (just like all of my other working views headers) :
<%# Page Title="" Language="VB" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage(Of XXXXX_XXXXX.Automatisation)" %>
Can anyone help me out ?
Thanks everyone for reading.
Check whether you have renamed your Model.
If you are using strongly typed-view then these kind of error is there.
Note:- Even though, you have added correct namespaces in your program, and most of the errors not specifically gives you the exact problem.
Does it work if you manually import the namespace (below #page):
<%# Import Namespace="System.Web.Mvc.Html" %>
My guess is that you have deleted a <% somewhere by mistake in your .aspx file.
Did you remember to schlep the little web.config that was in your views folder around? And did you remove any of the <add /> elements in the <pages><namespaces> bits of your web.config?

Can I use Extension Methods inline in an ASPX page?

Is it possible to do something like this inline in an ASPX page?
<%= Me.SomeExtensionMethod() %>
I can't seem to figure out how to get this to work properly. I'm receiving an error saying that "SomeExtensionMethod" is not a member of the current Page object. I've added the necessary <%# Import Namespace="..." %> directive at the top of my page. This Does work in code-behind.
This isn't vitally important, but it would be good to know how to do in the future.
Thanks!
Adding imports in the namespace works for me!
<%# Import Namespace="Foo.FooFoo" %>
Try closing the .aspx page and opening it up again as per this answer. If that improves things at all (e.g. enable intellisense) but doesn't solve it, please post any new errors you get.
You could also add the Public modifier to your Module or class definition. If you're using Modules, it really doesn't make sense to me that it would be required, but some discussion on this forum indicates that it might help.
If it's working in the codebehind, add the namespace to the function call:
<%=MyNamespace.ExtensionFcn("hello, world") %>
I'd do this before I'd modify the web.config.

Using ASP.NET MVC with generic views

I am currently investigating MVC for a new project we are starting. So far I like it, but I'm wondering about something.
The actual views that we will be displaying will not be known at design time, we will be specifying in a config file somewhere how to build these views. Is this pattern supported by MVC or do we need to know at design time exactly what data we will be viewing?
If not, can someone give me some pointers on what I should be looking at as most of the info I have assumes that you have a model/view that is defined during your design.
Regards,
Alex..
You can have your views weakly-typed... Your initial page directive on the view will look like:
<%# Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
... and then you can refer to data from your Controllers like this:
<%= ViewData["MyData"] %>
Is there some common interface that you are intending to pass to your view? If so, you can benefit from a using the generic ViewPage<> :
<%# Page Language="C#" Inherits="System.Web.Mvc.ViewPage<IamTheInterface>" %>
Then, you can use your interface to refer to your Model:
<%= Model.MyProperty %>
There is cool post in LosTechies.com about building an "autoform" with fields autogenerated from the Model properties. Take a look, it might be what you are looking for.

Resources