Following code is an example, I just want to know if this can be done.
I have an test.aspx file with this server side include tag;
<!--#include file="listOfCountries.htm" -->
Within listOfCountries.htm, I have:
<html>
<div>
<select id="countryList" runat="server">
<option></option>
...
</select>
</div>
</html>
Now, Is there a way to access "countryList" in test.aspx.cs file ?
On another note, say I didn't have the #include "Countries.htm" in test.aspx, is it possible to access the controls within Countries.htm from test.aspx.cs ? (i.e. accessing an external html file controls in cs)
As far as I'm aware, what you're asking for isn't possible as the include file isn't actually parsed as asp.net.
What you want to do is create a "User Control" by right clicking on your project, choosing "Add new Item" and choosing "Web User Control" from the window that appears.
Within your user control you can define the markup for "countries.htm", and then expose the contents of the <select> to your C# code.
Related
Is there anyway I can do the following code in razor?
<div>
<c:import url="http://hostName/HTML-file-name/" />
</div>
I would like to pull HTML from a given location and render it on a page. This should be possible...
Hope this makes sense...
In Razor, no. In HTML yes:
<div>
<iframe src="http://hostName/HTML-file-name/"></iframe>
</div>
Well actually you could use server side code to send an HTTP request to the remote resource and display the result inline:
<div>
#Html.Raw(new System.Net.WebClient().DownloadString("http://hostName/HTML-file-name/"))
</div>
But bear in mind that this will fetch only the content situated on the specified address. If this is for example an HTML page referencing external CSS, and javascript files, they will not be retrieved.
I am currently using <a> tag to click and navaigate as mentioned in below code.I want to navigate the below code in c# tag in page_prerender event based on id selected.could any one help on this?
<li>Category 1</li>
<li>Category 2</li>
<div id="cat1">
Content goes here
</div>
<div id="cat2">
Content goes here
</div>
something like if url doesn't contain '#' then
Response.Redirect("www.yoururl.com/Default.aspx#Cat2");
is that what you're looking for?
clicking on the <a> in html is really the same as just adding #Cat2 to the end of the URL , the browser knows what to do from there
I believe you need a url rewriting layer for how you have it. The <a> links are simply going to be a GET request with no further information. And even then you would need the links to be href="cat1" or href="#cat1".
The simplest alternative would be using <asp:linkbutton /> which can have server-side onclick events.
You might also look into AJAX requests, or use javascript to hide and display the sections, if the content is dynamic based on the request AJAX would be required there.
i'm programming in asp.net with umbraco and have a problem with master page.
i made a master page then added a web user master page that link in my default page.
at run time project in umbraco when i click on link saw this error :
Page not found
No umbraco document matches the url
'http://localhost:20771/WebForm1.aspx'
umbraco tried this to match it using this xpath query'/root/*
[#urlName = "webform1"] | /root// [#urlName = "webform1"]')
This page can be replaced with a custom 404 page by adding the id of
the umbraco document to show as 404 page in the
/config/umbracoSettings.config file. Just add the id to the
'/settings/content/errors/error404' element.
For more information, visit information about custom 404 on the
umbraco website.
This page is intentionally left ugly ;-)
i search in web and did not find any solution about it.
Check that your master page shows up in the admin area via Settings > Templates.
Then, check that your content page (in the admin Content section) has a template defined (under "Generic properties"). If it doesn't, and it doesn't let you select a template, then you need to allow that template to be used for that particular node type.
Go to Settings > Document Types, select your node type, and under "Allowed templates", select the template that you wish to us for the page (you may select a nested masterpage, it should still work just fine) - also make sure that the "Default allowed template" underneath is selected to your chosen template. Once you have hit "Save", go back to your node in the Content section, go to the "Generic properties" tab, and select the template you wish.
Umbraco lets you use any number of masterpages for rendering a content node. When creating new nodes, you then choose the template you wish to use (or use the default, as specified by following the above instructions).
You can also force a different template to be used at runtime, using the ?altTemplate=MyTemplateName querystring option on your page URL - handy for mobile sites, RSS views, and suchlike.
In Master.master page (it's general master page.) you can locate asp:ContentPlaceHolder
please attention to this code.Perhaps it's help you.
<div style="vertical-align: top;">
<umbraco:Macro ID="Macro1" Alias="NavigationControl" runat="server"></umbraco:Macro>
</div>
***<div>
<asp:ContentPlaceHolder ID="DefaultPageContent" runat="server">
</asp:ContentPlaceHolder>
</div>***
<div>
<asp:ContentPlaceHolder ID="TextPageContent" runat="server">
<!-- Insert default "ContactUsContent" markup here -->
</asp:ContentPlaceHolder>
</div>
<div>
<asp:ContentPlaceHolder ID="AtAGlanceContent" runat="server">
</asp:ContentPlaceHolder>
</div>
<div id="footer">
<uc6:FooterControl ID="FooterControl1" runat="server" />
</div>
</div>
</form>
I have a webpage with server accessible controls, see 'FileIconLink' below:
<body>
<p class="FirstTitle style5">Downloads:</p>
<div id="BreadcrumbDiv">
<p style="padding-left:5px; ">Page Loading...</p>
</div><!--/BreadcrumbDiv-->
<div id="DirLinksDiv">
<p><span class="SecondTitle">Files:</span></p>
<a runat="server" href="#" id="FileIconLink">File</a>
<% WriteFileLinks(); %>
<p><span class="SecondTitle">Folders:</span></p>
<a runat="server" href="#" id="FolderIconLink">Folder</a>
</div><!--/DirLinksDiv-->
</body>
<%RemoveHTMLTemplates(); %>
Both 'FileIconLink' and 'FolderIconLink' are templates of web controls which are copied by my code - such as <% WriteFileLinks(); %> above. How could these templates be permanently removed from the web page at run-time on the server without causing the error:
The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
Thanks in advance!
This is because you have <% %> inside the control you're trying to change. Instead of using <% %> in the aspx page, I would modify the code behind to add a literal control or something to the div, like:
DirLinks.Controls.Add(new LiteralControl(WriteFile()));
You should then be able to modify your control form the code behind.
Your inline code is executed during render.
But you probably want to get rid of the templates during Load.
Which means that the two techniques conflict.
Ultimately I realised my approach was wrong, as Cade Roux was alluding to, I needed to make up my mind where the templates were going to be used.
My solution was as follows:
Make controls for containing the results of my (previously inline) code.
Use templates in Page_Load to fill the controls described above.
Delete templates in Page_Load.
Do nothing inline.
The Page object has another function apart from Page_Load function called Page_PreRender, this function gets executed before Page_Load. So please try remove logic in this Page_PreRender function.
Please refer this link http://msdn.microsoft.com/en-us/library/system.web.ui.control.prerender.aspx
I have div inside which contactUsFAQ.html is included.
<div id="divContactUsFAQ" runat="server" >
<!--#include virtual="../HTML/ContactUsFAQ.html" -->
</div>
I need to include ContactIRP.html file and remove ContactUsFAQ.html on server side.
you can access the div as divContactUsFAQ from CodeBehind and it has .InnerHTML property containing <!--#include virtual="../HTML/ContactUsFAQ.html" --> - you can just assign what you need to .InnerHTML.