zoukankan      html  css  js  c++  java
  • 创建可重复使用的控件ascx-一页只能有一个服务器端 Form 标记?

    通过学习别人开发的的系统,发现建立一个文件夹如ascx,里面放有ascx文件(web用户控件文件),在其他页面可以灵活调用,特别是一些如head,foot,页面左边的menu等.所以,要研究下,顺便改进下以往的一个系统.

    1、在ASCX里面写代码的意义就是可以更灵活开发,而且可以更好的代码复用。你可以开发几个通用的用户控件,就和.net提供的那些控件一样,灵活的放到你用到的页面上。但建立文件的时候要注意

       html格式代码如:

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="head1.ascx.cs" Inherits="ascx_head_1" %>

    <script type="text/javascript">

    。。。

    </script>

    <asp:Label ID="Label1"

     </asp:Label>

    2、调用方法:

    先在<%@ Page Language="C#"...%>下注册

    <%@ Register TagPrefix="asc_head1" TagName="asc_head1" Src="~/ascx/head1.ascx" %>

    然后在需要用到该控件的地方声明:

    <asc_head1:asc_head1 ID="asc_head1" runat="server" />

    这样就可以了.

    3 \ 注意一点:如果ascx控件中有需要用到form,而aspx调用页面中也有form,则需要在ascx中先删除form标志然后采取

    <form runat="server">

      <uc1:usercontrol1 .../>

         <uc2:usercontrol2.../>

    </form>

    另外记得要注册控件到页面上:如:

    <%@ Register Src="usercontrol1.ascx" TagName="usercontrol1"
        TagPrefix="uc1" %>

     就这样就可以了。

    否则会出现 "一页只能有一个服务器端   Form   标记。”的错误提示"

    4\如果ascx中有超级链接,则需要记得加上 "~/"这个标志,这样,指向不会出错哦。否则,你会发现一大堆错误的.

    终于又有一点进步了。很是开心.鼓励下自己先.

  • 相关阅读:
    WCF 4.0中的动态发现服务WSDiscovery
    Windows Server 2008 R2 Server Core
    Open Source Web Design
    Windows Identity Foundation(WIF)正式发布
    是开始学习IronPython 的时候了
    IronPython 承载和消费WCF服务
    微博客程序 Yonkly
    如何启用匿名访问SQL Server Reporting Service 2008
    ASP.NET MVC 2 RC 发布
    SharePoint 2010 VHD下载
  • 原文地址:https://www.cnblogs.com/pyman/p/1645014.html
Copyright © 2011-2022 走看看