Pregunta

Estoy utilizando un control de servidor en una sola página web.forms. Tengo que utilizar este control en una página web.forms desde su servidor de control de una, aunque esto es en realidad un proyecto MVC. Así que creé una carpeta web.forms y poner mi nueva página en el mismo. a continuación, copio el código de ejemplo del control de la firma. Me sale el siguiente 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).

sé que el código funciona porque si me quita el atributo de identificación del control de servidor, ya no me da este error y hace que mi control. Pero necesito el atributo para el ID para que pueda llevar a cabo es posterior al evento ... Cualquier idea por qué?

Estoy utilizando este control de la firma. Aquí está el código 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>
¿Fue útil?

Solución

Abrir el archivo .ascx marcado del control de usuario. Se debería leer algo como esto:

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

Modificar a:

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

Aviso CodeFile -.> CodeBehind

Otros consejos

Alguien que conozco tuvo un problema parecido un tiempo atrás, y luego se encontraron con algo que podrían hacer algo en el BeginRequest el que ordena su problema y le permitió usar los controles de servidor en las vistas. Hice una búsqueda rápida por ella, y creo que este es lo que solía.

código de abajo:

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);
  }
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top