Asp.Net Viewstate Question

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
12/3/2009 11:45:20 AM
Gravatar
Total Posts 6

Asp.Net Viewstate Question

I have just started with mojoportal, so please accept my apologies if this question has been asked before.  I'm having a problem getting data back from a postback, and I need some help with it. I have MojoPortal 2.3.2.9 running on Windows Server 2008R2 with SQL Server.

Basically, what is happening is that I have built a custom control and simply added a calendar to it.  It isn't a Mojo-Calendar, just a simple asp.net one.  On selecting a date in the calendar and then clicking the the previous or next buttons in the calendar, the date doesn't remain selected.  Take the example of December 2009. The default calendar right now displays from November 29th to January 9th (don't ask me why there's an extra week in there).  If you click on January 7th and then click the "Next" symbol to display the next month, you would expect January 7th to still be selected.  This is how it works in as aspx page, and in an ascx page embedded in as aspx page.

However, that isn't what I am observing right now in mojoportal.  Every click after the date selection renders that date selection invalid, and sets the selected date to 01/01/0001. So, on selecting January 7th and then the next month button, I am seeing no date selected. The code I'm using to handle this is just the asp.net calendar control dropped into the HelloMojoSiteModule.ascx control with this code hooked up to the button : 

TextBox1.Text = "Date Selected is " + objCal.SelectedDate.ToShortDateString();

So, apologies for the long winded opening, but my question is this:  Is there something strange going on with the viewstate in mojoportal, or is there something fundamental that I'm missing in Asp.net?

12/3/2009 3:57:09 PM
Gravatar
Total Posts 18439

Re: Asp.Net Viewstate Question

Hi Dave,

Make sure you are calling Page.EnableViewstate = true; in your page load or init as it is disabled by default to reduce page size where possible.

If that does not solve it, then check if AutoEventWireup is false. I think it is in my hello world examples as I generally wire up events by hand out of habit and preference.

It will probably be best to wrap this functionality in an UpdatePanel else the postback can have unexpected consequences in other features that may live on the same page. If you are working with the source code you can find a good example in mojoPortal.Features.UI/Blog/BlogModule.ascx as I'm using the ASP.NET calendar for navigation in the blog also inside an UpdatePanel.

Hope it helps,

Joe

12/3/2009 4:27:31 PM
Gravatar
Total Posts 6

Re: Asp.Net Viewstate Question

ViewState was disabled, so I enabled it in the page load event and all is well now.  Thanks very much for the help with this Joe, it looks like I was beating my head against a brick wall all day for something incredibly... simple.

Might I be so bold as to suggest that you put something in the developer documentation to note the settings you have used which differ from what an asp.net developer would expect to find?

Thanks once again :-)

Dave

12/4/2009 7:42:49 AM
Gravatar
Total Posts 18439

Re: Asp.Net Viewstate Question

Good point. I've just added a note about this to the Hello World article, and the Overview of Feature Development.

Note that there is also a Web.config setting for DisablePageViewStateByDefault, which you could set to false, but I recommend leave it as true and enable viewstate only where needed.

Also note that the viewstate issue will be much better in ASP.NET 4.0. Currently to use viewstate it must be enabled at the page level and then you can disable it on a control by control basis to reduce the size of it for controls that don't need it. In ASP.NET 4 this will be reversed so that you can turn it off at the page level and then enable it only for controls that need it.

Best,

Joe

You must sign in to post in the forums. This thread is closed to new posts.