 |
| C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

June 13th, 2006, 11:50 PM
|
|
Registered User
|
|
Join Date: Jun 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
how to use view state in code behind files in C#
i am using a html control dropdownlist. i am not writing it inside form. so i put a hidden
value inside the form.on change of the dropdownlist,a funciton is called themechange(). and the value
which i selected will goto code behind files. when i select value form dropdown,the theme of the
site will change.
function themechange()
{
var s = document.getElementById("refer");
//alert(s);
document.getElementById("theme").value = s.options[s.options.selectedIndex].value;
//alert(document.getElementById("theme").value);
if(document.getElementById("theme").value != null)
{
document.forms(0).elements['themeresult'].value = document.getElementById("theme").value;
//alert(document.forms(0).elements['themeresult'].value);
}
document.forms(0).submit();
parent.window.location.reload();
}
</script>
<body onload="displaymsg();" onunload="if (newwin && !newwin.closed) newwin.close();if (timerWindow && !timerWindow.closed) timerWindow.close(); deleteSession();">
<DIV align=center>
<table border=0 cellpadding=0 cellspacing=0 width=100% height=100% class=footertable ID="Table2">
<tr>
<td colspan="5" bgcolor="#5A82AD" valign=middle>
<p align=center><small><small>Copyright
© Wipro Ltd. 2005. Best Viewed in 1024 x 800 I.E. 6.0 with SP1 & Above </small></small>
<SELECT id="themes" onchange="themechange();" name="refer">
<OPTION VALUE='' SELECTED>--- Select ---</OPTION>
<OPTION VALUE="theme1" id="theme1">Theme 1</option>
<OPTION VALUE="theme2" id="theme2">Theme 2</option>
<OPTION VALUE="theme3" id="theme3">Theme 3</option>
</SELECT>
</td>
</tr>
</table>
</div>
<div id='alert' style='display:none'></div>
<form name="frm" ID="Form1" runat="server">
<input type="hidden" name="timespent">
<input type="hidden" name="sessionid" value=sessionid>
<input type="hidden" name="MaxIncId" >
<input type="hidden" name="theme" >
<input type="hidden" name="themeresult">
</form>
codebehind file
if(Request["themeresult"] != null)
{
string result ;
result= Request["themeresult"];
switch(result)
{
case ("theme1"):
System.IO.File.Move("F:\\DEVELOPMENT 2.0\\e-Helpline\\_StyleLibrary\\stylesheet.css", "F:\\DEVELOPMENT 2.0\\e-Helpline\\_StyleLibrary\\stylesheettheme2.css");
System.IO.File.Move("F:\\DEVELOPMENT 2.0\\e-Helpline\\_StyleLibrary\\stylesheettheme1.css", "F:\\DEVELOPMENT 2.0\\e-Helpline\\_StyleLibrary\\stylesheet.css");
break;
case ("theme2"):
System.IO.File.Move("F:\\DEVELOPMENT 2.0\\e-Helpline\\_StyleLibrary\\stylesheet.css", "F:\\DEVELOPMENT 2.0\\e-Helpline\\_StyleLibrary\\stylesheettheme4.css");
System.IO.File.Move("F:\\DEVELOPMENT 2.0\\e-Helpline\\_StyleLibrary\\stylesheettheme3.css", "F:\\DEVELOPMENT 2.0\\e-Helpline\\_StyleLibrary\\stylesheet.css");
break;
case ("theme3"):
System.IO.File.Move("F:\\DEVELOPMENT 2.0\\e-Helpline\\_StyleLibrary\\stylesheet.css", "F:\\DEVELOPMENT 2.0\\e-Helpline\\_StyleLibrary\\stylesheettheme6.css");
System.IO.File.Move("F:\\DEVELOPMENT 2.0\\e-Helpline\\_StyleLibrary\\stylesheettheme5.css", "F:\\DEVELOPMENT 2.0\\e-Helpline\\_StyleLibrary\\stylesheet.css");
System.IO.File.Move("F:\\DEVELOPMENT 2.0\\e-Helpline\\_StyleLibrary\\stylesheettheme6.css", "F:\\DEVELOPMENT 2.0\\e-Helpline\\_StyleLibrary\\stylesheettheme5.css");
Page.RegisterStartupScript("test",@"<script>parent .window.location.reload();</script>");
break;
}
}
what my problem is, whenever i select theme, its changing but i need to toggle it again to bring back to original theme.
i have use viewstate to resolve the problem.
i have stylesheet.css where it is called all over the place. i have theme1.css, i rename the stylesheet.css to a temporary
stylesheet1.css and theme1.css to stylesheet.css.
now using viewstate, i need to bring back to the original theme.since if i select theme2 or theme3. it should work properly.
i just want to know , how viewstate is used in code behind files?
ajesh
|
|

June 14th, 2006, 02:28 AM
|
|
Registered User
|
|
Join Date: Jun 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
did anyone know how to use viewstate in switch case statement?
ajesh
|
|

June 14th, 2006, 06:03 AM
|
|
Registered User
|
|
Join Date: Jun 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
i will make my question little more clearer.
i have a drop down box having theme1,theme2 and theme3 as values.
the default stylesheet for the site is stylesheet.css
when i select theme1. the entire site get changed to theme1.
how i did this is
system.file.io.move(\\stylesheet.css, \\ stylesheet1.css)
system.file.io.move(\\stylesheettheme1.css, \\stylesheet.css)
now stylesheet.css contain stylesheettheme1.css
now i am problem is if i select theme2. again i will use move method to replace file,
system.file.io.move(\\stylesheet.css, \\ stylesheet2.css)
system.file.io.move(\\stylesheettheme2.css, \\stylesheet.css)
but here the stylesheet contain stylesheettheme1.css which i changed when i click theme1.
now when i select theme1, theme1 should apply my site and by using the viewstate property i want to change back to my default site.
how can i do that using viewstate.
can anyone please help me in this matter
thanx
ajesh
|
|

June 14th, 2006, 07:39 AM
|
|
Registered User
|
|
Join Date: Jun 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
i have a drop down list containing values theme1, theme2 , theme3
corresponding to theme1 is stylesheet1, theme2 is stylesheet2 etc
when i select theme1 the entire site get changed.then the viewstate value is say 1, now when i select theme2 or theme3 etc,
my viewstate value will be changed accordingly. now i have to comapre old viewstate with new viewstate.
the default stylesheet will change according to the selection in the dropdown. if i select theme1, default stylesheet will be changed to theme1. when i select theme2, default stylesheet should become theme2 but i am having theme1 as a default. so when i select theme2,it is overwriting theme1.it should not happen. in that case i need to use viewstate.
did anyone know how to solve my problem, its very urgent.
plz help me
thanx
|
|

June 20th, 2006, 06:00 AM
|
|
Authorized User
|
|
Join Date: Apr 2006
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
You use ViewState same way you use Session
ViewState["somevalueToStore"] = textBox1.Text;
....
string storedValue = (string)ViewState["someValueToStore"];
|
|
 |