سؤال

I have created several custom server controls in the past, these aren't user controls, so there is no "ascx" file to use. I'm given an MVC project to mimic the same kind of functionality that I wrote using the server controls. Basically the server control is a composite control, so it has a few textboxes, labels, checkboxes, and it has some javascript that comes with it. It also binds that functionality to a few webservices as well.

I'm wondering if it's possible to insert this control somewhere into an MVC page, or if I should rebuild this functionality from scratch purely using HTML helpers. I'm thinking the later.

I'm kind of a beginner when it comes to custom html helpers. Can I treat programming custom html helpers the same way as programming server side controls?

Btw, I need to add this example url to show what I'm talking about: http://msdn.microsoft.com/en-us/library/aa719734(v=vs.71).aspx

Whenever I mentioned server side controls, people are assuming native ASP.NET controls, or user controls, whereas I'm talking about custom server side controls.

I went with the custom server control approach a few months back because it made deployment extremely easy and easy to add to other .net projects. Since it wraps everything up in a dll, and all you'd have to do is recycle the pool. But it seems MVC says, "Nope, you aren't going to do that with me".

Any advice, tips, or links on how to approach this would be helpful.

Btw, I wouldn't be posting here if it was easy to find on the net. Most examples I found talked only about user controls or native asp server controls, nothing about custom server controls. I just don't want to do this functionality all over again and go through that headache.

هل كانت مفيدة؟

المحلول

You cannot use your ascx or dll custom controls in MVC. Mostly, because the lifetime of ASP.net controls is different. In MVC - controls just render HTML, They don't receive any postback, they don't save controlstate or viewstate. Even "Page" object does not exist in MVC.

MVC controls can accept parameters and render HTML.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top