Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
15
Anti forgery field breaks WebDatePicker
posted

Hi

   I have the following page.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DKTest.aspx.cs" Inherits="FMI.WSMplannet.Web.DKTest" %>

<!DOCTYPE html>

<html xmlns="">www.w3.org/.../xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">

<asp:ScriptManager runat="server" ID="scriptmanager1">

</asp:ScriptManager>
<h1>DK TEst</h1>

<ig:WebDatePicker ID="wdp" runat="server" >

</ig:WebDatePicker>

</form>
</body>
</html>

Which works fine. I can click on the arrow on the right of the text box and a little calendar popup displays. 

However when I add in cross-site forgery protection by adding a anti-forgery token and validating it like this. 

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DKTest.aspx.cs" Inherits="FMI.WSMplannet.Web.DKTest" %>

<!DOCTYPE html>

<html xmlns="">www.w3.org/.../xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">

<asp:ScriptManager runat="server" ID="scriptmanager1">

</asp:ScriptManager>
<h1>DK TEst</h1>

<ig:WebDatePicker ID="wdp" runat="server" >

</ig:WebDatePicker>
<%= System.Web.Helpers.AntiForgery.GetHtml() %>
</form>
</body>
</html>

and this. 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Helpers;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace FMI.WSMplannet.Web {
public partial class DKTest : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e)
{
if(IsPostBack) {
AntiForgery.Validate();
}
}

}
}

The date picker fails. It now longer brings up a calendar popup when I click on the right-hand side arrow. 

Parents
  • 1320
    Verified Answer
    Offline posted

    Hello David,

    After investigating this further, I determined that AntiForgery token could be set in the code behind. This could be achieved by adding a div tag with an id and runnat attribute in the form:

    <form id="form1" runat="server">

           <div id="AntiForgeryDiv" runat="server"></div>

           <ig:WebScriptManager ID="WebScriptManager1" runat="server"></ig:WebScriptManager>

           <ig:WebDatePicker ID="WebDatePicker1" runat="server">

           </ig:WebDatePicker>

    </form>

    And setting the AntiForgery.GetHtml() to the innerHtml of the div in the Page_Init method:

    protected void Page_Init(object sender, EventArgs e)

        {

            AntiForgeryDiv.InnerHtml = AntiForgery.GetHtml().ToString();

        }

    protected void Page_Load(object sender, EventArgs e)

        {       

            if (IsPostBack)

            {

                AntiForgery.Validate();

            }

        }

    By adding the AntiForgery  the following way, the calendar of the WebDatePicker is opened as expected.

    Please let me know if you need any further information regarding this matter.

    Regards,

    Monika Kirkova,

    Infragistics 

Reply Children