Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional 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
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 30th, 2007, 03:55 PM
Friend of Wrox
 
Join Date: Apr 2005
Location: Fort Walton Beach, FL, USA.
Posts: 190
Thanks: 0
Thanked 0 Times in 0 Posts
Default Javascript and View State

Anyone: Help please:

Is it possible for a javascript function in ASP.NET 2.0 , to access it's page's ViewState?

If yes, can you show me a line of code showing how?

Thanks.

VV


  #2 (permalink)  
Old March 31st, 2007, 01:48 AM
Imar's Avatar
Wrox Author
Points: 72,038, Level: 100
Points: 72,038, Level: 100 Points: 72,038, Level: 100 Points: 72,038, Level: 100
Activity: 50%
Activity: 50% Activity: 50% Activity: 50%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,080
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi VictorVictor,

Since it's just a hidden field, you can do this:

alert(document.getElementById('__ViewState').value );

However, it's a hashed and signed value, so while it's possible to look into the viewstate to see what it contains, I don't think you're able to make any changes to it without breaking your application.

Why do you want to change view state directly? Can you explain what you're trying to accomplish? There may be better ways to do the same thing, possibly by changing controls on the page directly.

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
  #3 (permalink)  
Old April 1st, 2007, 05:02 PM
Friend of Wrox
 
Join Date: Apr 2005
Location: Fort Walton Beach, FL, USA.
Posts: 190
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar:

Thanks for the response.

Down below I have written up the problem from which I made this thread.

After I made the writeup I realized that this is a fairly complicated and specific problem and I do not expect you or anyone else to take the time to solve it.

I had hoped (my usual approach) that there is a simple quick answer to it.

So, unless it is something that you can see right away that has a simple answer or that I am overlooking, don't spend a lot of your valuable time on this.

So, just for entertainment value here's the description of the problem at hand.

------------------------------------------------------------------------------------
I have a webpage in an interactive website which contains calendars and other user selectable options (dropdown boxes, radio buttons, etc.) for a user to select.

These selections are used to dynamically build a select statement which returns a data table object that is used to populate a gridview.

Both paging and sorting are enabled for the gridview which may display from zero thru many thousands of lines (hopefully not thousands, but the capability must be there).
The gridview displays up to 10 lines on the webpage; more than that, paging takes over.

At any point in time while viewing or sorting, the user may click an <asp:button> to print the gridview. (This requires using the ‘onclientclick’ event with a small client javascript function for IE7 print services.). I am using the same button’s ‘onclick’ event (at the server) to set the gridview’s pagesize property from 10 to 20,000 lines and to disable paging. This allows all the lines in the gridview to be printed.

One further complication is that I want the column header the user selects (to sort) to also cause the entire column to become bolded and italicized both on the page and on the printed output.

Everything works fine, except the ability to bold and italicize the selected gridview column both on the screen and from the printer. The ViewState refreshes the page after a round trip to the server with the selected column unbolded and not italicized.

Things I have tried to use to cause the gridview to display a bold and italicized column (all fail):

1. The httpcontext.current.session object (to hold a value or a bolded, italicized
        column). (Can’t access it.)

2. The ViewState. Changing it dynamically to contain a bolded, italicized column
        in the gridview. (It’s hashed and therefore unusable.)

3. The <asp:button> (both the onclientclick code and the clientclick code) to
        change the gridview’s row’s then cell’s then font’s properties. (ViewState
        overrides.)

I don’t know anything about AJAX, although that is the next thing I will learn how to use. So, if it is possible, I want to finish this app without AJAX.
----------------------------------------------------------------------------------

Thanks for any help on this.

VV





  #4 (permalink)  
Old April 1st, 2007, 11:44 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

VV,

If you are already doing a full postback to order the column, then I think it's just a matter of specifying the column style of the grid column to apply the font formatting you desire. You just have to determine what column to affect based on the sort expression.

-Peter
  #5 (permalink)  
Old April 2nd, 2007, 01:26 AM
Imar's Avatar
Wrox Author
Points: 72,038, Level: 100
Points: 72,038, Level: 100 Points: 72,038, Level: 100 Points: 72,038, Level: 100
Activity: 50%
Activity: 50% Activity: 50% Activity: 50%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,080
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Yeah, that seems to make sense; do a full post back, rebind the grid, and then when the page reloads, print the page at the client with JavaScript.

What are IE7 print services? Do you mean the JavaScript Print() method? Or is this something new in IE7?

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
  #6 (permalink)  
Old April 2nd, 2007, 08:24 AM
Friend of Wrox
 
Join Date: Apr 2005
Location: Fort Walton Beach, FL, USA.
Posts: 190
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Peter and Imar:

Sorry, I misled you on the printing terminology.
When the user presses the html print button the onclientclick code is simply,
"window.print(document)". Since the app runs in an IE7 environment I assume that IE7 handles the request to print the document. This works fine.

As for your other suggestions, I am going to explore them and will post here, the outcome.

Thanks.

VV

  #7 (permalink)  
Old April 2nd, 2007, 12:21 PM
Imar's Avatar
Wrox Author
Points: 72,038, Level: 100
Points: 72,038, Level: 100 Points: 72,038, Level: 100 Points: 72,038, Level: 100
Activity: 50%
Activity: 50% Activity: 50% Activity: 50%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,080
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

You can do what Microsoft does on many of their MSDN articles. When you click the Print link, the page posts back and then invokes the Print dialog.

You can do this with RegisterStartUpScript that calls print, like this:

ClientScript.RegisterStartupScript(this.GetType(),
      "myOnloadKey", "<script>window.print();</script>");

You can call this in the handler for the PostBack, like a Button's click event. Inside that handler, you can rebind the grid with all of the data and register the "startup" script, so when the page reloads, it will automatically trigger the print dialog.

Hope this helps,

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
  #8 (permalink)  
Old April 2nd, 2007, 02:26 PM
Friend of Wrox
 
Join Date: Apr 2005
Location: Fort Walton Beach, FL, USA.
Posts: 190
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar:

Thanks for the additional method for the printing problem. I was successful in using yours and planoie's recent suggestions. So now I have two ways to do it. Feast or famine.

I was in the middle of writing up the successful implementation when your second method arrived.

We kinda strayed off my original query about using the ViewState, so I made a writeup and started a new thread here a few moments ago, titled: How to print from a dynamic gridview at run time. Hopefully other beginners will not have to struggle.

You guys get all the credit for the idea which I implemented. Thanks again.

VV


  #9 (permalink)  
Old April 2nd, 2007, 02:34 PM
Imar's Avatar
Wrox Author
Points: 72,038, Level: 100
Points: 72,038, Level: 100 Points: 72,038, Level: 100 Points: 72,038, Level: 100
Activity: 50%
Activity: 50% Activity: 50% Activity: 50%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,080
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

You're more than welcome.

And thanks for posting the follow up; I am sure this will benefit a future user of this forum.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 


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
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
Refresh Button and View State Sunil Sabir General .NET 3 August 16th, 2004 02:40 PM



All times are GMT -4. The time now is 03:33 PM.


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