Custom Web Control Probs

bri189a

Senior Contributor
Joined
Sep 11, 2003
Messages
1,004
Location
VA
So I found this nice (and free for all) WYSIWYG control (two js files), cross browser safe, really nice. So I thought to myself, if I could make this into a custom web control so I can use it any project easily that would be really cool.

Anyway, I got the design part down (no thanks to MSDN and its so called help file), but the run-time part is where I'm having issues. I decided for simplicity, and since I don't know another way (can't use an external file), to embed the javascript in a user control, and then on my render of the custom control create an instance of that user control which contains the script that has all the code that displays the WYSIWYG stuff and renders it, thus getting all the javascript out to the client and the WYSIWYG control drawn via the JavaScript embeded in the user control.

Problem is that nothing happens. If I initialize some other web control and render it, it works fine, but the user control doesn't:

(in Render(HtmlTextWriter output) method)
Works:
Image i = new Image();
i.RenderControl(output);

Doesn't Work:
jsControl j = new jsControl(); //user control that hold script
j.RenderControl(output);

Now to me it should work, but nothing is output to the browser.

Ideally I wouldn't want to put all the script out to the client, I rather use an external file (as most people do on large scripts so they are cached rather than having to be downloaded on each page) but I'm not sure how and if that is even possible with a custom web control.

This isn't my area of expertise, any guidance/help on this would be much appreciated!

Update:
I don't like this idea but it's the only thing I can think of to avoid sending the scripts down to the client...I'm thinking that this control when first intitialized will check to see if a folder exists that contains the script files, if it doesn't it will call a procedure that creates the folder and creates a copy of the files, same with the images it uses. I don't like the idea of a control creating folders and files for a web app, but I'm trying to avoid sending the script to the client any other way than <script language="javascript" src="soruce.js"></script> method. As we all know this method allows caching of the script rather than it having to be downloaded with every page. This also ensures that their are default images. Like I said I don't like the idea but I don't know what else to do.
 
Last edited:
You need to call this.Page.RegisterClientScript("script name",script); to emit your script into the page. Are the scripts really so big that you are worried about how long it will take the user to download them?
 
Rodenberg said:
You need to call this.Page.RegisterClientScript("script name",script); to emit your script into the page. Are the scripts really so big that you are worried about how long it will take the user to download them?
About 800 lines all together. Caching scripts is just good practice.
 
I'm not into using javascript that isn't 100% dynamically generated by my business logic for use in server controls, so I'm not familiar with all of the nuances that the hardcore javascript programmer would be.

I can't cache my javascript for obvious reasons, what gets emitted by my server controls can be drastically different depending on the site, page, and the end user.
 
Back
Top