Frage

Einer meiner großen beefs mit ASP.NET ist, dass es es schwierig macht, die Kontrollen einer Seite über große Mengen an prefixing IDs zu organisieren. Ich habe in der Vergangenheit große und komplizierten Anstrengungen unternommen, um zu versuchen, dies zu lindern, aber ich würde eine solche Lösung, die einfacher zu implementieren ist. Also, ich frage mich:

Ist es möglich, eine Benutzersteuerung in dem Code-Behind eines ASPX zu definieren, und es dann in der ASPX benutzen? Ich denke, wahrscheinlich nicht ... Ich kann es nicht an der Arbeit.

War es hilfreich?

Lösung

No. You must create a user control in it's own .ascx file.

Though if you wish wish to create a web control, you can define that in whichever .cs/.vb file you want. Though for the sake of your coworkers being able to find your code, I might suggest it live in it's own file anyways.

NOTE: I would question the validity of "it difficult to organize the controls of a page beyond excessive amounts of prefixing IDs". This is what templated controls (repeater, datalist, etc) are for. They will implement INamingContainer and thus will enable you to name controls with the same name, but different scope. There's some good info here...

Andere Tipps

There has to be an existing ASP.NET user control defined, and you can dynamically load it. That's about as much as dynamic capabilities with user controls that you have. You can also leverage custom controls, which really gives you the complete control over the rendered UI. However, not rendering complete ID's can have subsequent issues with the client/server integration, depending on what you are trying to do.

Also, to customize the ID, you can leverage ASP.NET 4.0's ClientIDMode property: http://msdn.microsoft.com/en-us/library/system.web.ui.control.clientidmode.aspx

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top