creating design templates in asp.net
I need to apply different design templates for my front page of website in asp.ne开发者_运维百科t.
This should be done on selection of different image buttons available on the front page....
When user registers our website,the front page should display 4 image buttons with design preview and when user selects particular button,appropriate design template should be applied to the website.... but contents should remain same on every design template....
<link rel="stylesheet" href="default.css" type="text/css">
<script type="text/javascript">
$(document).ready(function() {
$("#style1").click(function() {
$("link[rel=stylesheet]").attr({href : "style1.css"});
});
$("#style2").click(function() {
$("link[rel=stylesheet]").attr({href : "style2.css"});
});
</script>
<input type="button" id="style1" value="style 1" />
<input type="button" id="style2" value="style 2" />
I'd so something like this with jQuery (or do it with regular javascript, but I'm always worried I'll forget some obscure cross-browser bit) and multiple css sheets to define your "design templates". Could probably also accomplish it by switching out your MasterPage but that's messy and not the right tool for the job imo.
thanks.... but can u tell me how to achieve this in asp.net without using javascript or jquery.. single code with several design templates...
Without javascript method:
Create a base masterpage and have your "design templates" be other masterpages that inherit from that. Have buttons/links that post your page back and pass a value via form field or query string that indicates which masterpage to load. (do this in PreInit)
void Page_PreInit(Object sender, EventArgs e)
{
this.MasterPageFile = string.format( "~/{0}.master",Request.QueryString["master"]);
}
精彩评论