访问 ASP.Net 用户控件

发布于 2024-10-10 17:49:18 字数 392 浏览 4 评论 0原文

嘿伙计们,
我创建了一个 CustomFileUpload 类,它是从原始 FileUpload 类继承的,我不得不说它实际上不是一个 UserControl 它是一个简单的类,如下所示,

using System;
using System.Web;

public class CustomFileUpload : System.Web.UI.WebControls.FileUpload
{
    public string Directory { get; set; }
}

我需要知道如何在页面中使用该控件,当我们创建用户控件时,可能类似于 <@Registe ...

Hey guys,
I've created a CustomFileUpload class which is inherited from the original FileUpload class, I'm gonna have to say it's not actually a UserControl it's a simple class which can be seen below

using System;
using System.Web;

public class CustomFileUpload : System.Web.UI.WebControls.FileUpload
{
    public string Directory { get; set; }
}

I need to know how I can use the control in my page, maybe something like <@Registe ... when we create a usercontrol.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

陌路终见情 2024-10-17 17:49:18

这称为自定义服务器控件。您可以阅读有关它们的深入演练。您需要将服务器控件驻留在与您的项目分开的程序集中,然后将该程序集引用到您的项目中。

将控件放在页面上要使用的语法是:

<%@ Register Assembly="YourAssemblyName" TagPrefix="myControl" Namespace="YourNamespaceName"%>

然后您可以引用该控件:

<myControl:CustomFileUpload .... />

执行此操作的一个简单方法是将控件添加到工具箱。然后您可以将控件从工具箱拖到任何页面上。注册表将自动创建。将控件添加到工具箱

  1. 右键单击​​控件应驻留的工具箱选项卡,选择“选择项目”。 (您可以创建一个新选项卡或使用现有选项卡)。
  2. 选择浏览
  3. 并选择程序集,单击打开
  4. 您的控件现在应该出现在工具箱选项卡中。

This is called a custom server control. You can read an indepth walkthrough about them. You will need to have the server control reside in an assembly that is separate from your project and then reference the assembly into your project.

The syntax you want to use to put the control on the page is:

<%@ Register Assembly="YourAssemblyName" TagPrefix="myControl" Namespace="YourNamespaceName"%>

Then you can reference the control:

<myControl:CustomFileUpload .... />

An easy way to do this is to add the control to your toolbox. Then you can drag the control from the toolbox onto any page. The Register will be created automatically. To add the control to the toolbox

  1. Right click on the toolbox tab where the control should reside, select choose items. (You can create a new tab or use an existing one).
  2. Select Browse
  3. Browse to and select your assembly, click Open
  4. Your control should now appear in the toolbox tab.
你的笑 2024-10-17 17:49:18

您可以执行以下操作:

<%@ Register TagPrefix="my" Namespace="My.Namespace" Assembly="MyAssembly" %>

您也可以在配置级别执行此操作:

<system.web>
  <pages>
    <controls>
      <add tagPrefix="my" namespace="My.Namespace" assembly="MyAssembly" />
    </controls>
  </pages>
</system.web>

然后在您的页面中使用:

<my:CustomFileUpload runat="server" ... />

You can do:

<%@ Register TagPrefix="my" Namespace="My.Namespace" Assembly="MyAssembly" %>

You can also do this at the config level:

<system.web>
  <pages>
    <controls>
      <add tagPrefix="my" namespace="My.Namespace" assembly="MyAssembly" />
    </controls>
  </pages>
</system.web>

Then use in your page:

<my:CustomFileUpload runat="server" ... />
憧憬巴黎街头的黎明 2024-10-17 17:49:18

您需要将您的类放入命名空间中并像这样注册它

<%@ Register tagprefix="tagprefix" Namespace="Your Namespace" Assembly="The Assembly" %>

然后您可以使用这样的控件

<tagprefix:CustomFileUpload runat="server" />

http://msdn.microsoft.com/en-us/library/c76dd5k1(v=VS.100).aspx

You need to put your class in a Namespace and register it like this

<%@ Register tagprefix="tagprefix" Namespace="Your Namespace" Assembly="The Assembly" %>

Then you can use the control like this

<tagprefix:CustomFileUpload runat="server" />

http://msdn.microsoft.com/en-us/library/c76dd5k1(v=VS.100).aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文