Two days ago,a colleague of mine tried to publish an asp.net website (which is built in VS2008 using framework 3.5) to our server,he configured everything in IIS (he made sure that the selected asp.net version is 2.0) and launched the website..at first it was working great but when he tried to click on a specific treeview...BOOM..:
"Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request."
In that page there were these control: a TreeView and a Placeholder,when the user selects any node then it's controls will be created dynamically into that placeholder..for the first time it's working fine but when (s)he select another node then that issue appears.
He called me to help him with this issue,for me this is the first time I see such an issue,scratch my head then I decided to eliminate the possibilities of this issue one by one,at the development machine it's working perfectly,he published the website at the local IIS and again..it's working perfectly,I took a copy of the website and published it into my laptop but no issues at all,so this is means that it's not an issue in the code.
So there is something missing/wrong in our server [it has Windows Server 2003],we went to the server and checked on the web-config and the configurations on IIS...nothing wrong so far,so I decided to check if the framework 3.5 is installed or not and the answer: it wasn't installed
Of course he assumed that it was installed and there was nothing to tell if it wasn't from the "ASP.Net version" in IIS because frameworks 3.0 and 3.5 will not be listed there [2.0 will be listed there instead],the only way to check if it was installed or not is to search for the framework in this path:[WINDOWS Folder]\Microsoft.NET\Framework or check if it was installed in Add or remove programs.
The obvious solution for his case:
We installed Framework 3.5 SP1 into our server,did a restart to the machine and it worked !
If anyone faced the same issue and solved it using the same solution or with a different one please post it here to share experience.
I stepped by this page: http://www.filamentgroup.com/lab/date_range_picker_using_jquery_ui_16_and_jquery_ui_css_framework/
and let me tell you,this is one of the best and coolest daterangepicker in the web in my opinion,they did a great job with extending the original jQuery UI DatePicker.Of course I made enhancements to the original plugin (fixed few bugs) and added a new option (Clear) to clear the textbox.
In this article I well use that updated plugin and show you how to use it in asp.net..you will definitely like it.
So,What do I need?
1- jQuery library : you can use 1.3.2 or 1.4.2 which is the latest version so far,in my article I will use the latest version.
2- jQuery UI library (1.8): As I mentioned earlier,daterangepicker plugin is based on the original jQuery UI DatePicker so that library should be included into your page.
3- jQuery DateRangePicker plugin : you can go to the author page or use the modified one (it's included in the attachment),in this article I will use the modified one.
4- Visual Studio 2005 or later : very funny :D[as if you don't already knows that],anyway in my article I will use VS 2008.
in the attachment,I included all CSS and JS files so don't worry.
How to use it?
Then add this html:
As you can see,it includes TextBox1 which we are going to attach the daterangepicker to it,2 labels to show you later on by code on how to read the date from the textbox and set it to the labels
Now we have to attach the daterangepicker to the textbox by using jQuery (Note:visit the author's website for more info on daterangerpicker's options and how to use them):
Finally,add this C# code:
protected void SubmitButton_Click(object sender, EventArgs e)
if (TextBox1.Text.Trim().Length == 0)
string selectedDate = TextBox1.Text;
string splittedDates = selectedDate.Split("-".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
if (splittedDates.Count() == 2 && DateTime.TryParse(splittedDates, out startDate) && DateTime.TryParse(splittedDates, out endDate))
FirstDate.Text = startDate.ToShortDateString();
SecondDate.Text = endDate.ToShortDateString();
//maybe the client has modified/altered the input i.e. hacking tools
if (DateTime.TryParse(selectedDate, out selectedDateObj))
FirstDate.Text = selectedDateObj.ToShortDateString();
SecondDate.Text = string.Empty;
//maybe the client has modified/altered the input i.e. hacking tools
This is the way on how to read from the textbox,That's it!
1-Why did you add this style?:
For two reasons:
- To show the Daterangepicker in a smaller size because it's original size is huge.
- To show you how to control the size of it.
2- Can I change the theme?
yes you can,you will notice that I'm using Redmond theme which you will find it in jQuery UI website,visit their website and download a different theme,you may also have to make modifications to the css of daterangepicker,it's all yours.
3- Why did you add a font size to the textbox?
To make the design look better,try to remove it and see by your self.
4- Can I register the script at codebehind?
yes you can
5- Why do I need to set attributes (readonly) and (unselectable) for the textbox ?
readonly will make the textbox not editable by the user,unselectable will block the blinking typing cursor from appearing if the user clicked on the textbox,you will notice that both attributes are necessary to be used together,you can't just use one of them...for logical reasons of course.
Finally,I hope everyone liked the article and as always,your feedbacks are always welcomed and if anyone have any suggestions or made any modifications that might be useful for anyone else then please post it here and at at the author's website.
P.S : There is no harm in posting comments
I use placeholders very much in many projects,but in one of the projects I was asked to reset the controls within a specific placeholder to their original state after the user has finished from inserting his/her data.
As everyone of us know,to keep the controls within a placeholder from disappearing after postbacks you have to recreate them,we add such a code in i.e. page_load,the controls will be recreated and their values will be loaded from viewstate (for some of them like textbox,checkboxs,..etc) automatically,that placeholder contains only textboxs so what I need is to block/ loading/clear that viewstate after inserting the data.
First thought: Customizing placeholder
I thought about it and tried overriding many methods but no success at all...maybe I'm missing something not sure.
Second thought: recreate the controls 2 times:
In page_load,I recreate the controls within that placeholder then in button click (the button that saves user's data) I recreate them once more and it worked!
I just thought of sharing my experience in that case with everyone in case anyone needed it,any better suggestion(s) is welcomed.