Ala'a Alnajjar

Everything about ASP.Net

  • Cannot implicitly convert type 'string' to 'System.Web.UI.WebControls.TextBox'

    I faced this issue yesterday,it was very strange because it doesn't make sense at all.

    I have a master page and 1 content page,in that content page there is only one TextBox and an Ajax Editor (from ASP.NET AJAX Control Toolkit),no more no less.

    I tried to run the page but the debugger doesn't compile at all,it keeps showing this error message:

    Cannot implicitly convert type 'string' to 'System.Web.UI.WebControls.TextBox'

    It was hopeless,there isn't any server side code or even any JavaScript blocks,nothing!

    After a long analysis at the source/html of my page and trying every possibility I finally found what caused the issue that I won't guess it at all:

    EMPTY TITLE for my content page

    That is what caused the issue,I was surprised,after removing/setting a value for the title the problem solved!

    I hope my experience with this issue might help someone else,if anyone face the same issue and solved it in the same way or in a different way then please post it here,this will surely help others as well.


  • How to fix "Validation(): Element 'xxxx' is not supported" and "Unrecognized tag prefix or device filter 'asp'"

    Since about a month ago,I started to get validation warnings at design time on server controls (any control actually) within the html design view for VS 2010 or later,intellisense on all controls would not work at all,the messages like:

    Unrecognized tag prefix or device filter 'asp'
    Validation(): Element 'Label' is not supported.
    Validation(): Element 'GridView' is not supported

    The compilation done successfully but the warnings still exist and intellisense is not working at the source tab

    I tried to reset the settings of Visual studio ,disabled all extensions and few other ideas but none of them solved the issue,I got stuck.

    I did a search over the internet about this issue and found this article on Doug Kennard's blog:

    Splendid,that article is a life savior,the idea is to remove the folder "ReflectedSchemas" from paths:

    Win XP : C:\Documents and Settings\{username}\Application Data\Microsoft\VisualStudio\10.0\ReflectedSchemas

    Win Vista / 7: C:\Users\{username}\AppData\Roaming \Microsoft\VisualStudio\10.0\ReflectedSchemas

    Note: make sure that "Show hidden files, folders, and drives" is selected from Folder Options,also don't forget to close VS before deleting the folder.

    This solution should work for any Visual studio version,keep in mind that you have to use the correct VS version number i.e

    Visual studio 2010 : %appdata%\Microsoft\VisualStudio\10.0\ReflectedSchemas
    Visual studio 2012: %appdata%\Microsoft\\VisualStudio\11.0\ReflectedSchemas
    Visual studio 2013: %appdata%\Microsoft\VisualStudio\12.0\ReflectedSchemas


  • Failed to load viewstate.The control tree into which viewstate is being loaded...etc

    Two days ago,a colleague of mine tried to publish an website (which is built in VS2008 using framework 3.5) to our server,he configured everything in IIS (he made sure that the selected version is 2.0) and launched the 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'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.


  • How to use jQuery Date Range Picker plugin in

    I stepped by this page: 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 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.

    Note: in the attachment,I included all CSS and JS files so don't worry.

    How to use it?


    Then add this html:
    First Date:
    Second Date:

    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;
            if (selectedDate.Contains("-"))
                DateTime startDate;
                DateTime endDate;
                string[] splittedDates = selectedDate.Split("-".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                if (splittedDates.Count() == 2 && DateTime.TryParse(splittedDates[0], out startDate) && DateTime.TryParse(splittedDates[1], out endDate))
                    FirstDate.Text = startDate.ToShortDateString();
                    SecondDate.Text = endDate.ToShortDateString();
                    //maybe the client has modified/altered the input i.e. hacking tools
                DateTime selectedDateObj;
                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?:

    A: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?
    A: 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?
    A: To make the design look better,try to remove it and see by your self.

    4- Can I register the script at codebehind?
    A: yes you can

    5- Why do I need to set attributes (readonly) and (unselectable) for the textbox ?

    A: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


  • Reset the controls within asp placeholder

    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.


P.S. In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: