Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > WebControl with CSS and Javascript

Reply
Thread Tools

WebControl with CSS and Javascript

 
 
patrick.sannes@gmail.com
Guest
Posts: n/a
 
      06-12-2006
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
 
 
 
 
Peter Bromberg [C# MVP]
Guest
Posts: n/a
 
      06-12-2006
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




"(E-Mail Removed)" wrote:

> 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
 
 
 
 
bruce barker \(sqlwork.com\)
Guest
Posts: n/a
 
      06-12-2006
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)



<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> 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
 
patrick.sannes@gmail.com
Guest
Posts: n/a
 
      06-13-2006
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);
}
}


}

> 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
 
patrick.sannes@gmail.com
Guest
Posts: n/a
 
      06-13-2006
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.


http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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);
> }
> }
>
>
> }
>
> > 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
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
WebControl with CSS and Javascript patrick.sannes@gmail.com ASP .Net 4 06-13-2006 09:00 AM
WebControl with CSS and Javascript patrick.sannes@gmail.com ASP .Net Web Controls 4 06-13-2006 09:00 AM
Trapping an Exception ocurring in a Webcontrol at the Page or parent WebControl level. ASP .Net 2 01-31-2005 06:34 PM
WebControl inside of WebControl and attaching events Kasabaarde Sumta ASP .Net Building Controls 0 12-13-2004 09:51 PM
Can a webcontrol (webcontrol.dll) have a configuration file? Luis Ramírez. ASP .Net Building Controls 2 07-06-2004 04:35 PM



Advertisments