Mombu the Programming Forum sponsored links

Go Back   Mombu the Programming Forum > Programming > WebControl with CSS and Javascript
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 12th August 17:26
patrick.sannes
External User
 
Posts: 1
Default WebControl with CSS and Javascript



Hi there,

I'm creating a custom control with Javascript and CSS. It will be a
nice overlay calendar with a result textbox. My main problem is that
the Javascript is realy huge, so you want to include it in a seperate
..js file. But, then it is not bound with the WebControl.... What is the
normal way to solve this??

Regards,
Patrick
  Reply With Quote


  sponsored links


2 12th August 17:27
peter bromberg [c# mvp]
External User
 
Posts: 1
Default WebControl with CSS and Javascript



You can embed the javascript file into the control assembly as an embedded
resource if you like.
Depending on which version of the framework you are working with , you can
get this out with GetManifestResourceStream.

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
  Reply With Quote
3 12th August 17:27
bruce barker \(sqlwork.com\)
External User
 
Posts: 1
Default WebControl with CSS and Javascript


the standard way is:

RegisterClientScriptBlock("mycontroljs","<script
src=\"mycontrol.js\""></script>");

or the new

RegisterClientScriptResource(typeof(this),"mycontr ol.js");


both of these methods handle being called more than once so that the
<script> tag is only output once. they also have methods to determine if
they have been called already for the same tag.

-- bruce (sqlwork.com)
  Reply With Quote
4 12th August 17:28
patrick.sannes
External User
 
Posts: 1
Default WebControl with CSS and Javascript


I did it with this peace of code I found, but then I get it inline (and
it is a lot, so it would be nicer to get it in a .js file... I realy
don't know if it is possible...

private void RegisterScript(String scriptName)
{
if
(!this.Page.ClientScript.IsClientScriptBlockRegist ered(scriptName))
{
using (System.IO.StreamReader reader = new
System.IO.StreamReader(this.GetType().Assembly.Get ManifestResourceStream(this.GetType(),
scriptName)))
{
String script = "<script language='javascript'
type='text/javascript'>\r\n<!--\r\n" + reader.ReadToEnd() +
"\r\n//-->\r\n</script>";
this.Page.RegisterClientScriptBlock(scriptName,
script);
}
}


}
  Reply With Quote
5 12th August 17:28
patrick.sannes
External User
 
Posts: 1
Default WebControl with CSS and Javascript


Solved it...

Added
[assembly:
System.Web.UI.WebResource("Company.WebControls.pop calendar.js",
"text/js", PerformSubstitution = true)]
To the AssamblyInfo.cs
And
string scriptLocation =
Page.ClientScript.GetWebResourceUrl(this.GetType() ,
"Company.WebControls.popcalendar.js");

Page.ClientScript.RegisterClientScriptInclude("Com pany.WebControls.popcalendar.js",
scriptLocation);
To the WebControl class.
  Reply With Quote


  sponsored links


Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666