Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 13th, 2006, 11:50 PM
Registered User
 
Join Date: Jun 2006
Location: Bangalore, Karnataka, India.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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 &amp;&amp; !newwin.closed) newwin.close();if (timerWindow &amp;&amp; !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
                            &copy; Wipro Ltd. 2005. Best Viewed in 1024 x 800 I.E. 6.0 with SP1 &amp; 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

Reply With Quote
  #2 (permalink)  
Old June 14th, 2006, 02:28 AM
Registered User
 
Join Date: Jun 2006
Location: Bangalore, Karnataka, India.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

did anyone know how to use viewstate in switch case statement?

ajesh

Reply With Quote
  #3 (permalink)  
Old June 14th, 2006, 06:03 AM
Registered User
 
Join Date: Jun 2006
Location: Bangalore, Karnataka, India.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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


Reply With Quote
  #4 (permalink)  
Old June 14th, 2006, 07:39 AM
Registered User
 
Join Date: Jun 2006
Location: Bangalore, Karnataka, India.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
  #5 (permalink)  
Old June 20th, 2006, 06:00 AM
Authorized User
 
Join Date: Apr 2006
Location: , , .
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You use ViewState same way you use Session

ViewState["somevalueToStore"] = textBox1.Text;
....
string storedValue = (string)ViewState["someValueToStore"];

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
View state problem rabbit3 ASP.NET 2.0 Professional 0 October 23rd, 2007 08:55 PM
Javascript and View State VictorVictor ASP.NET 2.0 Professional 8 April 2nd, 2007 02:34 PM
The View State is invalid for this page and might ITladybug ASP.NET 2.0 Professional 0 March 1st, 2006 02:10 PM
Session State|View State|Do I have other options? rockon ASP.NET 1.x and 2.0 Application Design 2 October 5th, 2005 07:10 PM



All times are GMT -4. The time now is 05:32 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.