2010-02-26 88 views
1

我在單個web.forms頁面上使用服務器控件。我必須在web.forms頁面上使用這個控件,因爲它是一個服務器控件,儘管這實際上是一個MVC項目。所以我創建了一個web.forms文件夾並將其放入新頁面。然後,我複製簽名控件中的示例代碼。我得到以下錯誤:在MVC項目的webform中使用webform用戶控件

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的屬性,所以我可以執行後發生的事情......任何想法爲什麼?

我正在使用this簽名控制。這裏的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> 

回答

1

打開用戶控制的的.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 - >代碼隱藏。

0

我認識的人有類似的問題而回,然後他們發現的東西,他們可以做在解決了他的問題BeginRequest東西,並允許他使用服務器在視圖中控制。我做了一個快速搜索,我相信this是他用過的。下面

代碼:

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); 
    } 
} 
+0

我不想把我的服務器控件放在視圖頁面中,而是一個真正的web.forms頁面......只是爲了澄清。 – Gabe 2010-02-26 20:27:58