您何时需要。ascx文件,您将如何使用它们?

时间:2023-01-15 09:50:31

When building a website, when would it be a good idea to use .ascx files? What exactly is the .ascx and what is it used for? Examples would help a lot thanks!

在建立网站时,什么时候使用.ascx文件是一个好主意?.ascx到底是什么?它的用途是什么?例子会很有帮助,谢谢!

7 个解决方案

#1


86  

It's an extension for the User Controls you have in your project.

它是项目中用户控件的扩展。

A user control is a kind of composite control that works much like an ASP.NET Web page—you can add existing Web server controls and markup to a user control, and define properties and methods for the control. You can then embed them in ASP.NET Web pages, where they act as a unit.

用户控件是一种复合控件,其工作原理与ASP很相似。NET Web页面—您可以向用户控件添加现有的Web服务器控件和标记,并为控件定义属性和方法。然后可以将它们嵌入到ASP中。网络网页,它们作为一个整体。

Simply, if you want to have some functionality that will be used on many pages in your project then you should create a User control or Composite control and use it in your pages. It just helps you to keep the same functionality and code in one place. And it makes it reusable.

简单地说,如果您想要在项目中的许多页面上使用某些功能,那么您应该创建一个用户控件或复合控件,并在页面中使用它。它只是帮助您在一个地方保持相同的功能和代码。它使它可重复使用。

#2


11  

We basically use user controls when we have to use similar functionality on different locations of an app. Like we use master pages for consistent look and feel of app, similarly to avoid repeating the same functionality and UI all over the app, we use usercontrols. There might me much more usage too, but I know this one only...

当我们需要在应用的不同位置使用类似的功能时,我们基本上会使用用户控件。就像我们使用母版来保持应用的外观和感觉一致一样,为了避免在整个应用中重复相同的功能和UI,我们使用用户控件。也许还有更多的用法,但我只知道这个……

For example, let's say your site has 4 levels of users and for each user there are different pages under different directories with different access mechanisms. Say you are requesting address info for all users, then creating address fields like Street, City, State, Zip, etc on each page. That would be a repetitive job. Instead you can create it as an ascx file (ext for user control) and in this control put the necessary UI and business code for add/update/delete/select the address role wise and then simply reference it all required page.

例如,假设您的站点有4个级别的用户,每个用户在不同的目录下有不同的页面,使用不同的访问机制。假设您正在为所有用户请求地址信息,然后在每个页面上创建地址字段,如Street、City、State、Zip等。那将是一项重复的工作。相反,您可以将其创建为ascx文件(用于用户控件的ext),在此控件中,将必要的UI和业务代码用于添加/更新/删除/选择地址角色,然后简单地引用所有需要的页面。

So, thought user controls, one can avoid code repetition for each role and UI creation for each role.

因此,考虑到用户控件,可以避免每个角色的代码重复和每个角色的UI创建。

#3


9  

Ascx-files are called User Controls and are meant for reusability and also for making complex aspx-pages less complex (lift out some part of the page). They could also be beneficial for something called donut caching, that is when you would like to cache a certain part of a page.

Ascx-files被称为用户控件,用于重用,也用于使复杂的aspx-pages变得不那么复杂(去掉页面的某些部分)。它们还可以用于所谓的甜甜圈缓存,也就是您希望缓存页面某一部分的时候。

#4


2  

If you have a block of code+html that appears on several pages and is sort of independent of that page (say a block of latest news items), you could copy/paste the code to every page.

如果您有一个代码块+html,它出现在几个页面上,并且在某种程度上独立于该页面(比如最新的新闻项目块),您可以将代码复制/粘贴到每个页面。

It is however better to put that code in its own block and just include that block on every page that needs it. That "block" is an ascx file.

但是,最好将代码放在自己的块中,并在需要它的每个页面中包含该块。那个“块”是一个ascx文件。

#5


1  

ASCX files are server-side Web application framework designed for Web development to produce dynamic Web pages.They like DLL codes but you can use there's TAGS You can write them once and use them in any places in your ASP pages.If you have a file named "Controll.ascx" then its code will named "Controll.ascx.cs". You can embed it in a ASP page to use it:

ASCX文件是为Web开发设计的服务器端Web应用程序框架,用于生成动态Web页面。他们喜欢DLL代码,但你可以使用标签,你可以写一次,并在你的ASP页面的任何地方使用它们。如果您有一个名为“Controll”的文件。然后它的代码将命名为“controller .ascx.cs”。你可以将它嵌入到一个ASP页面中使用:

#6


1  

One more use of .ascx files is, they can be used for Partial Page caching in ASP.NET pages. What we have to do is to create an ascx file and then move the controls or portion of the page we need to cache into that control. Then add the @OutputCache directive in the ascx control and it will be cached separately from the parent page. It is used when you don't want to cache the whole page but only a specific portion of the page.

ascx文件的另一个用途是,它们可以用于ASP中的部分页面缓存。网络页面。我们需要做的是创建一个ascx文件,然后移动需要缓存到该控件的页面的控件或部分。然后在ascx控件中添加@OutputCache指令,它将与父页面分开缓存。当您不想缓存整个页面时,只使用该页面的特定部分。

#7


-2  

When you are building a basic asp.net website using webcontrols is a good idea when you want to be able to use your controls at more then one location in your website. Separating code from the layout ascx files will be holding the controls that are used to display the layout, the cs files that belong to the ascx files will be holding the code that fills those controls.

当你想要在网站的多个位置使用你的控件时,使用webcontrols来构建一个基本的asp.net网站是一个好主意。从布局ascx文件中分离代码将持有用于显示布局的控件,属于ascx文件的cs文件将持有填充这些控件的代码。

For some basic understanding of usercontrols you can try this website

对于用户控制的一些基本了解,您可以尝试这个网站

#1


86  

It's an extension for the User Controls you have in your project.

它是项目中用户控件的扩展。

A user control is a kind of composite control that works much like an ASP.NET Web page—you can add existing Web server controls and markup to a user control, and define properties and methods for the control. You can then embed them in ASP.NET Web pages, where they act as a unit.

用户控件是一种复合控件,其工作原理与ASP很相似。NET Web页面—您可以向用户控件添加现有的Web服务器控件和标记,并为控件定义属性和方法。然后可以将它们嵌入到ASP中。网络网页,它们作为一个整体。

Simply, if you want to have some functionality that will be used on many pages in your project then you should create a User control or Composite control and use it in your pages. It just helps you to keep the same functionality and code in one place. And it makes it reusable.

简单地说,如果您想要在项目中的许多页面上使用某些功能,那么您应该创建一个用户控件或复合控件,并在页面中使用它。它只是帮助您在一个地方保持相同的功能和代码。它使它可重复使用。

#2


11  

We basically use user controls when we have to use similar functionality on different locations of an app. Like we use master pages for consistent look and feel of app, similarly to avoid repeating the same functionality and UI all over the app, we use usercontrols. There might me much more usage too, but I know this one only...

当我们需要在应用的不同位置使用类似的功能时,我们基本上会使用用户控件。就像我们使用母版来保持应用的外观和感觉一致一样,为了避免在整个应用中重复相同的功能和UI,我们使用用户控件。也许还有更多的用法,但我只知道这个……

For example, let's say your site has 4 levels of users and for each user there are different pages under different directories with different access mechanisms. Say you are requesting address info for all users, then creating address fields like Street, City, State, Zip, etc on each page. That would be a repetitive job. Instead you can create it as an ascx file (ext for user control) and in this control put the necessary UI and business code for add/update/delete/select the address role wise and then simply reference it all required page.

例如,假设您的站点有4个级别的用户,每个用户在不同的目录下有不同的页面,使用不同的访问机制。假设您正在为所有用户请求地址信息,然后在每个页面上创建地址字段,如Street、City、State、Zip等。那将是一项重复的工作。相反,您可以将其创建为ascx文件(用于用户控件的ext),在此控件中,将必要的UI和业务代码用于添加/更新/删除/选择地址角色,然后简单地引用所有需要的页面。

So, thought user controls, one can avoid code repetition for each role and UI creation for each role.

因此,考虑到用户控件,可以避免每个角色的代码重复和每个角色的UI创建。

#3


9  

Ascx-files are called User Controls and are meant for reusability and also for making complex aspx-pages less complex (lift out some part of the page). They could also be beneficial for something called donut caching, that is when you would like to cache a certain part of a page.

Ascx-files被称为用户控件,用于重用,也用于使复杂的aspx-pages变得不那么复杂(去掉页面的某些部分)。它们还可以用于所谓的甜甜圈缓存,也就是您希望缓存页面某一部分的时候。

#4


2  

If you have a block of code+html that appears on several pages and is sort of independent of that page (say a block of latest news items), you could copy/paste the code to every page.

如果您有一个代码块+html,它出现在几个页面上,并且在某种程度上独立于该页面(比如最新的新闻项目块),您可以将代码复制/粘贴到每个页面。

It is however better to put that code in its own block and just include that block on every page that needs it. That "block" is an ascx file.

但是,最好将代码放在自己的块中,并在需要它的每个页面中包含该块。那个“块”是一个ascx文件。

#5


1  

ASCX files are server-side Web application framework designed for Web development to produce dynamic Web pages.They like DLL codes but you can use there's TAGS You can write them once and use them in any places in your ASP pages.If you have a file named "Controll.ascx" then its code will named "Controll.ascx.cs". You can embed it in a ASP page to use it:

ASCX文件是为Web开发设计的服务器端Web应用程序框架,用于生成动态Web页面。他们喜欢DLL代码,但你可以使用标签,你可以写一次,并在你的ASP页面的任何地方使用它们。如果您有一个名为“Controll”的文件。然后它的代码将命名为“controller .ascx.cs”。你可以将它嵌入到一个ASP页面中使用:

#6


1  

One more use of .ascx files is, they can be used for Partial Page caching in ASP.NET pages. What we have to do is to create an ascx file and then move the controls or portion of the page we need to cache into that control. Then add the @OutputCache directive in the ascx control and it will be cached separately from the parent page. It is used when you don't want to cache the whole page but only a specific portion of the page.

ascx文件的另一个用途是,它们可以用于ASP中的部分页面缓存。网络页面。我们需要做的是创建一个ascx文件,然后移动需要缓存到该控件的页面的控件或部分。然后在ascx控件中添加@OutputCache指令,它将与父页面分开缓存。当您不想缓存整个页面时,只使用该页面的特定部分。

#7


-2  

When you are building a basic asp.net website using webcontrols is a good idea when you want to be able to use your controls at more then one location in your website. Separating code from the layout ascx files will be holding the controls that are used to display the layout, the cs files that belong to the ascx files will be holding the code that fills those controls.

当你想要在网站的多个位置使用你的控件时,使用webcontrols来构建一个基本的asp.net网站是一个好主意。从布局ascx文件中分离代码将持有用于显示布局的控件,属于ascx文件的cs文件将持有填充这些控件的代码。

For some basic understanding of usercontrols you can try this website

对于用户控制的一些基本了解,您可以尝试这个网站