c# - Asp.NET user control referenced from another project/dll has NULL properties -


trying move common custom control new class library (also tried new web project), other projects can use it, properties null when used in project. searching similar questions unfortunately not solve problem.

i register new control in our web.base.config project-a

<add tagprefix="controls" namespace="comp.userwebcontrols.controls" assembly="comp.userwebcontrols"  /> 

the comp.userwebcontrols added project reference in project-a (i tried adding build dll reference in project-a, no difference)

the markup looks like

<asp:content id="content4" contentplaceholderid="rightplaceholder" runat="server"> <controls:uxmycontrol id="testingthing" runat="server" /> 

in code behind, "testingthing" control instantiated, properties null (labels, textboxes, etc)

normally, if control within same project (project-a) register control this:

<add tagprefix="contols" tagname="uxmycontrol" src="~/controls/uxmycontrol.ascx"/> 

and in codebehind control object looks fine, properties instantiated , working expected.

i cant src="mypath" when using assembly think has it.

how can seperate out control new assembly/project/solution other projects can use it.

any appreciated thanks!

i don't think can take user control (e.g. .ascx file) , put class library shared amongst different apps.

instead, need write custom control. class (a single .cs file, no associated ascx) derives control (or variant of control - example, derive dropdownlist if wanted make own custom dropdown list control).

differences: https://msdn.microsoft.com/en-us/library/aa651710(v=vs.71).aspx

there's msdn article here: https://msdn.microsoft.com/en-us/library/aa479318.aspx discusses how create custom control user control if aren't feeling comfortable idea of it.

it outlines steps follows:

  1. write user control would, typically using visual studio designer.
  2. test using simple page before trying deploy it.
  3. deploy application precompile it.
  4. grab user control's assembly produced deployment step, , you're done: have custom control.
  5. finally, use custom control in other apps same way use custom controls.

if wanted have collection of controls , don't want separate dll each, use decompiler such reflector @ what's been generated , copy/paste class library of shared controls.

you should able register tagprefix , namespace showed: <add tagprefix="controls" namespace="comp.userwebcontrols.controls" assembly="comp.userwebcontrols" />

and should ready go.

if user control wasn't particularly complicated, i'd tempted read about pure code custom controls , try , write instead of trying grab , decompile dll.

i think reason you're getting null values viewstate , page lifecycle. thing struggled in webforms, dynamically loaded controls, figuring out in lifecycle you're supposed load them. seem recall if adding them dynamically in page_load example, they'd seem work never persist values across postbacks, page_init worked fine.

so - create custom control, single class file user control, rid of traces of .ascx , should go.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -