开发者

Web Control to Class Library (c# / ASP.NET)

开发者 https://www.devze.com 2023-02-07 19:45 出处:网络
Ive had a search, but cant really seem to find a decent answer. Basically i have a web application with a user control in it (with .ascx, .ascx.cs and .ascx.designer files).

Ive had a search, but cant really seem to find a decent answer.

Basically i have a web application with a user control in it (with .ascx, .ascx.cs and .ascx.designer files).

The user control ascx has some javascrip开发者_运维百科t and basic markup.

Is it possible to move the entire thing into a class library and call it from code-behind?

The only alternative I can see is to create all of the markup / javascript in code-behind.


You have 3 options as far as I know with my 3rd option behind less than helpful as I don't remember how to do it.

"Best" option (IMHO): Convert it to a server control (as you said, all in the code behind). This will give you more flexibility in the long term and you don't have to store your JavaScript in the code behind itself; you can store it in any type of resource file to load in so it doesn't have to turn into a nasty soup of code.

"Hacky" option: Create a web application and put your user control in it. You can reference this application as you would any class library and you would be able to access your controls (granted, it may generate some odd namespaces when you attempt to reference).

"Semi-Hacky" option: See, the code front is not automatically available to the code behind in a class project. I believe there is a way to, hackily, link these up but I don't remember how to do so.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号