I thought HTML5 was backwards compatible - so why does Sharepoint 2010 knock me sprawling to the ground when I try to use the new input type "date"?

That's apparently the problem here; my Web Part project throws a runtime exception on the "Control control = Page.LoadControl(_ascxPath);" line here:

public class PostTravelWizardWebPart : WebPart
    // Visual Studio might automatically update this path when you change the Visual Web Part project item.
    private const string _ascxPath = @"~/_CONTROLTEMPLATES/PostTravelWizard/PostTravelWizardWebPart/PostTravelWizardWebPartUserControl.ascx";

    protected override void CreateChildControls()
        Control control = Page.LoadControl(_ascxPath);

The exception is, "System.Web.HttpParseException was unhandled by user code Message='date' is not a valid type for an input tag."

Manzanas del Camino del Toro!

This happens after adding this code:

0) Added the "runat="server"" to this HTML in the *.ascx file:

<input type="date" style="width=100px" id="formfilledout" name="formfilledout" runat="server" />

1) Added this C# helper method:

// from http://stackoverflow.com/questions/4955769/better-way-to-find-control-in-asp-net
// for getting html elements by id
public static class ControlExtensions
    public static Control FindControlRecursive(this Control control, string id)
        if (control == null) return null;
        //try to find the control at the current level
        Control ctrl = control.FindControl(id);

        if (ctrl == null)
            //search the children
            foreach (Control child in control.Controls)
                ctrl = FindControlRecursive(child, id);

                if (ctrl != null) break;
        return ctrl;

2) Called that method from the Web Part's (*.ascx.cs file) Page_Load method like so:

protected void Page_Load(object sender, EventArgs e)

    . . .

    Control ctrl = this.FindControlRecursive("formfilledout");
    bool ctrlIsNull = false;
    if (null == ctrl)
        ctrlIsNull = true;

I have a breakpoint in the "ctrlIsNull = true;" line, but it doesn't even reach that. It immediately fails.

Even when I commented out the entire section above, though (everything in Page_Load() below "base.OnPreRender(e);" it still fails in the same way.

So I removed the "runat="server"" directive from the "formfilledout" input date, and that solved it - so why does adding "runat="server"" to an html input element of type "date" cause the sky to fall?

There's got to be an easier way to access html elements (and their values) than jumping through these flaming hoops and running through these pummeling gauntlets.

  • 1
    You mention that this is on SharePoint 2010. Does the website run in IE8 compatability mode? I'm not sure that IE8 accepts type="date" for input fields. – user2536 Sep 18 '15 at 11:04
  • How would I find that out (if it runs in IE8 compatibility mode)? My guess, though, is yes, as most here use IE, and some are probably in need of an upgrade. – B. Clay Shannon Sep 18 '15 at 14:00
  • 1
    If you open the site in your IE browser and press F12, there should popup a tool at the bottom of your IE browser, and in it along the top it should say Compatability mode: IE-something. Another way to check is by View Source and then search for X-UA-Compatible - you should be able to find something looking like this in the source: <meta http-equiv="X-UA-Compatible" content="IE=9">. If it says content="IE=8" then that could be the cause. – user2536 Sep 18 '15 at 14:40
  • Yes, it does say "IE=8" (in the "View Source" - I see no popup via F12). Dang Dinosaurs! They're worse than the previous catch-all culprits (teenagers). – B. Clay Shannon Sep 18 '15 at 17:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.