Last post Mar 21, 2007 04:16 PM by Cattrah
Mar 19, 2007 05:03 PM|Cattrah|LINK
Mar 20, 2007 04:10 PM|Cattrah|LINK
Well I managed to get it working, not exactly like I wanted but it works for all intensive purposes. The only thing I haven't figured out yet is how to get the Design view of the page the control is being used on to show like it would if it were a user control.
Right now it's just a tan box that says "MyControl - mycontrolid" when I would rather it show me how it looks for real. Anyway, here's the exact setup I had to do in order to accomplish this:
And that's how I got it to work for me. I was detailed in my steps here because I didn't find any indepth resource about how to do this specific thing, even though it was mentioned all over the place as being possible and easy. I guess I was just dense or
whatever, but hopefully it helps someone else. I'll post again if I ever figure out the design view thing, or if anyone knows what I'm missing regarding that I'd sure love to hear about it. Maybe if I'm abmitious I'll try to get the toolbox thing to work....probably
won't though. Hope this is useful to SOMEONE!
Mar 21, 2007 04:16 PM|Cattrah|LINK
Okay I just know some .net framework guy is gonna twitch an eyeball or two at what I did here but it kinda works! Gah, it feels like such a hack, I dunno if I should even post it. To my boss, it just wasn't quite good enough to have a little tan box be the
way the control looked in design view and the lack of toolbox items really bugged him sooooo I did an evil evil thing. I created a new project, a Web Control Library, since everything I've read basically says a library is the only thing that can be used in
the toolbox, at least I hadn't figured out how to wire up the toolbox hints successfully to a usercontrol to try that out. And then in this library I copied the UserControl dll I compiled up in my last post, made a reference to it. Created a new Web User Control.
Made a new instance of one of the controls from my dll and exposed the properties in this new Web Control. I overrode the createchild controls and only added the user control and then the render contents I used mycontrol.RenderControl(output). Build this new
project and sure enough I can open the resuting dll and pick out the controls and stick em in the toolbox, drag and drop to the page, set the properties I exposed and it all builds and works fine. The only little trip up now is in design view it's no longer
a tan box, it seems like it wants to show me what the control looks like but for some reason the .Text property keeps telling me Object Reference Not set to Instance of an Object, even though I can set that property just fine in the codebehind and it works
when I run it on the page its in, it's just not perfectly pretty in the design view yet. I'm sure I'll probably figure it out after some more tinkering and research. So what does this really save me? I guess not a whole lot, but it'll sure be a lot easier
to make changes to the controls when necessary because I can just change the user control which is easy and friendly to work with, compile, re-reference in the library, make property changes if necessary, compile and I'm done, one dll to rule them all. Here's
the code for my web control that uses my user control dll.