Include aspx file in another aspx file
<% if (Session["desig"].ToString() == "Developer"){%>
<td>
<select name='zone' id="zone" onchange="showLoc(this.value,'mlodg_loc')">
<option value="Select Zone">Select Zone</option>
<option value="East">East</option>
<option value="West">West</option>
<option value="North">North</option>
<option value="South1">South1</option>
<option value="South2">South2</option>
<option value="South3">South3</option>
</select>
</td>
<%}
else
{%>
<td>
<select name='zone' id="Select1" onchange="showLoc(this.value,'mlodg_loc')">
<option value="Select Zone">Select Zone</option>
<option value="<%#Session["zone"]%>"><%# Session["zone"].ToString() %></option>
</select>
</td>
<%}%>
the above code works fine, if i write it directly i tried to write this code in another file and in the main file i did Response.WriteFile("zone.aspx")
How can I include it in some way to include, and also would like to know how best to write the above statements.
Thankyou
source to share
Response.WriteFile
just writes files to the Http response stream without parsing it.
While it is possible to use "Server side" includes in asp.net ( <!--#include file="xxx.ext" -->
), it has the smell of classic asp code to it IMO.
The best way to get component reuse .aspx
is with User Control (.ascx) .
Similar question here
Update
Response.WriteFile
great for simple Html, .css or .js, but not for code containing C # or .Net object references (you used Session
in your code) like
Response.WriteFile("HtmlSnippet.html")
where HtmlSnippet.html
is
<p>In breaking news, scientists have discovered a planet in
<a href='http://en.wikipedia.org/wiki/Alpha_Centauri_Bb'>Alpha Centauri</a>
</p>
Server side use Include, eg. <!--#include file="file.inc" -->
will allow you to do something like this in your .inc file:
<% if (Session["desig"].ToString() == "Developer"){ %>
You are a Developer!!
<% } %>
However, it is recommended that you use a custom control ( .ascx
), which allows you to do the same thing as the back end, but only in a much more reusable, object oriented, and testable way. Your reusable control will be a first class object with properties, methods, and the ability to raise events. You will need some research here.
source to share
Response.WriteFile does not process server side code. It just takes the html content and feeds it to the browser. If your code contains blocks of code that need to be processed by the server, you can use this handy function:
<div ID="menuContent" runat="server">
<!-- #Include virtual="/menu.aspx" -->
</div>
In my menu.aspx file, I have raw html and some C # codeblocks and ASP will resolve them after the content is inserted into the page. Great huh?
source to share