views:

181

answers:

2

I am using a server control on a single web.forms page. I have to use this control on a web.forms page since its a server control, although this is actually a MVC project. So I created a web.forms folder and put my new page in it. I then copy the example code from the signature control. I get the following error:

The base class includes the field 'ctrlSign', but its type (WebSignatureCapture.SignatureControl) is not compatible with the type of control (ASP.signaturecapture_signaturecontrol_ctlsignature_ascx).

I know the code works because if I removed the ID attribute from the server control, it no longer gives me this error and my control renders. But I need the attribute for the ID so I can perform is post event... Any ideas why?

I am using this signature control. Here's the web.forms code...

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="KahunaCentralTIDRevamp.SignatureCapture.Index" %>

<%@ Reference Control="~/SignatureCapture/SignatureControl/ctlSignature.ascx" %>
<%@ Register TagPrefix="uc" TagName="Signature" Src="~/SignatureCapture/SignatureControl/ctlSignature.ascx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>
    <title>Signature Application Demo</title>
</head>
<body>

    <form id="frmOrder" method="post" runat="server">
    <div>
        Please Sign Below:
    </div>
    <div>
        <uc:Signature ID="ctrlSign" SignHeight="150" SignWidth="300" SignatureCodePath="~/SignatureCapture/SignatureControl/"
            SavePath="~/SignatureCapture/" SignatureFileFormat="Gif" runat="server" />
        <%--    <uc:Signature id="ctlMySignature" PenColor="Red" PenWidth="2" BackColor="Yellow" SignWidth="300" SignHeight="150"
                            SavePath="~/Signatures/" SignatureCodePath="~/SignatureControl/" SignatureFileFormat="Gif" Runat="server"></uc:Signature>--%>
    </div>
    <div>
        <input type="button" value="  Re-Sign " onclick="ClearSignature();">
        <asp:Button runat="server" ID="btnSave" Text=" Save " onmousedown="document.getElementById('btnSave').value = 'Wait...';"
            OnClientClick="DirectSave();" OnClick="btnSave_Click" />
    </div>
    </form>

    <script language="javascript" type="text/javascript">
        // This is the method that is directly called, this will save signature
        // and then call server code to do further processing. You can change
        // the delay of 5 seconds as per your needs
        function DirectSave() {
            SaveSignature();

            var date = new Date();
            var curDate = null;

            // delay of 5 seconds, 5000 milisecons, change as per requirement
            do { curDate = new Date(); }
            while (curDate - date < 5000);

            return true;
        }
    </script>

</body>
</html>
A: 

Someone I know had a similar problem a while back, and then they found something that they could do something in the BeginRequest which sorted his problem and allowed him to use server controls in views. I did a quick search for it, and I believe that this is what he used.

Code below:

void Application_BeginRequest(object sender, EventArgs e)
{
  var form = HttpContext.Current.Request.Form;

  form.GetType().GetProperty("IsReadOnly", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(form, false, null);

  // Refinement 1:
  foreach (var key in form.AllKeys.Where(key => key.Contains("$")))
  { 
    var value = formkey;
    form.Remove(key);
    var newKey = key.Substring(key.LastIndexOf("$") + 1); 
    form.Add(newKey, value);
  }
}
Dan Atkinson
I am not trying to put my server control in a view page, but an actual web.forms page...Just to clarify.
gmcalab
+1  A: 

Open the .ascx markup file of the user control. It should read something like this:

<%@ Control 
    Language="C#" 
    AutoEventWireup="true" 
    CodeFile="ctlSignature.ascx.cs" 
    Inherits="WebSignatureCapture.SignatureControl.ctlSignature" %>

Modify it to:

<%@ Control 
    Language="C#" 
    AutoEventWireup="true" 
    CodeBehind="ctlSignature.ascx.cs" 
    Inherits="WebSignatureCapture.SignatureControl.ctlSignature" %>

Notice CodeFile -> CodeBehind.

Darin Dimitrov