我使用单个web.forms页上的服务器控制。我不得不使用它,因为服务器控件的web.forms页面上这种控制,虽然这实际上是一个MVC项目。所以,我创建了一个文件夹web.forms,把我的新的一页了。然后,我的例子代码签名控制复制。我收到以下错误:

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).

我知道代码的作品,因为如果我从服务器控件中删除ID属性,它不再给我这个错误,我的控件呈现。但我需要的属性的ID,所以我可以执行的事件后......任何想法,为什么?

我使用的 签名控制。这里的web.forms代码...

<%@ 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>
有帮助吗?

解决方案

打开用户控制的的.ascx标记文件。它应是这样的:

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

它修改为:

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

注意的CodeFile - >代码隐藏

其他提示

我认识的人有类似的问题而回,然后他们发现的东西,他们可能会在的的BeginRequest 这解决了他的问题,并允许他使用服务器控件的意见。我做了快速搜索,而我相信是他用的东西。

代码如下:

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);
  }
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top