在MVC项目表单使用Web窗体的用户控件 [英] Using webform user control on webform in MVC Project

查看:114
本文介绍了在MVC项目表单使用Web窗体的用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

 的基类包括字段ctrlSign,但其类型(WebSignatureCapture.SignatureControl)不与控件的类型(ASP.signaturecapture_signaturecontrol_ctlsignature_ascx)兼容。

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

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

 <%@页面语言=C#AutoEventWireup =真codeBehind =Index.aspx.cs继承=KahunaCentralTIDRevamp.SignatureCapture.Index%GT ;<%@参考控制=〜/ SignatureCapture / SignatureControl / ctlSignature.ascx%GT;
<%@注册标签preFIX =UC变量名=签名SRC =〜/ SignatureCapture / SignatureControl / ctlSignature.ascx%GT;
<!DOCTYPE HTML PUBLIC - // W3C // DTD HTML 4.0过渡// ENGT&;
< HTML和GT;
< HEAD>
    <标题>签名中的应用演示与LT; /标题>
< /头>
<身体GT;    <表ID =frmOrder方法=邮报=服务器>
    < D​​IV>
        请在下面:
    < / DIV>
    < D​​IV>
        < UC:签名ID =ctrlSignSignHeight =150SignWidth =300签名codePATH =〜/ SignatureCapture / SignatureControl /
            SavePath =〜/ SignatureCapture /SignatureFileFormat =GIF=服务器/>
        <% - < UC:签名ID =ctlMySignaturePenColor =红PenWidth =2背景色=黄色SignWidth =300SignHeight =150
                            SavePath =〜/签名/签名codePATH =〜/ SignatureControl /SignatureFileFormat =GIF=服务器>< / UC:签字> - %GT;
    < / DIV>
    < D​​IV>
        <输入类型=按钮值=重新登录的onclick =ClearSignature();>
        < ASP:按钮=服务器ID =btnSave文本=保存onmousedown事件=的document.getElementById('btnSave')值='等待...';
            的OnClientClick =DirectSave();的OnClick =btnSave_Click/>
    < / DIV>
    < /表及GT;    < SCRIPT LANGUAGE =JavaScript的类型=文/ JavaScript的>
        //这是直接调用的方法中,这将节省签名
        //然后调用服务器code做进一步处理。您可以更改
        // 5秒的延迟,按您的需求
        功能DirectSave(){
            SaveSignature();            VAR日期=新的日期();
            VAR CURDATE = NULL;            // 5秒,5000 milisecons延迟,变化按要求
            做{CURDATE =新的日期(); }
            而(CURDATE - 日期和LT 5000);            返回true;
        }
    < / SCRIPT>< /身体GT;
< / HTML>


解决方案

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

 <%@控制
    语言=C#
    AutoEventWireup =真
    codeFILE =ctlSignature.ascx.cs
    继承=WebSignatureCapture.SignatureControl.ctlSignature%GT;

修改为:

 <%@控制
    语言=C#
    AutoEventWireup =真
    codeBehind =ctlSignature.ascx.cs
    继承=WebSignatureCapture.SignatureControl.ctlSignature%GT;

的通知codeFILE - > codeBehind

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>

解决方案

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.

这篇关于在MVC项目表单使用Web窗体的用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆