|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
WebControl with CSS and JavascriptHi 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 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. -- Show quoteHide quoteCo-founder, Eggheadcafe.com developer portal: http://www.eggheadcafe.com UnBlog: http://petesbloggerama.blogspot.com "patrick.san***@gmail.com" 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 > > 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.IsClientScriptBlockRegistered(scriptName)) { using (System.IO.StreamReader reader = new System.IO.StreamReader(this.GetType().Assembly.GetManifestResourceStream(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); } } } Show quoteHide quote > 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 > Solved it...
Added [assembly: System.Web.UI.WebResource("Company.WebControls.popcalendar.js", "text/js", PerformSubstitution = true)] To the AssamblyInfo.cs And string scriptLocation = Page.ClientScript.GetWebResourceUrl(this.GetType(), "Company.WebControls.popcalendar.js"); Page.ClientScript.RegisterClientScriptInclude("Company.WebControls.popcalendar.js", scriptLocation); To the WebControl class. patrick.san***@gmail.com wrote: Show quoteHide quote > 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.IsClientScriptBlockRegistered(scriptName)) > { > using (System.IO.StreamReader reader = new > System.IO.StreamReader(this.GetType().Assembly.GetManifestResourceStream(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 > > the standard way is:
RegisterClientScriptBlock("mycontroljs","<script src=\"mycontrol.js\""></script>"); or the new RegisterClientScriptResource(typeof(this),"mycontrol.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) <patrick.san***@gmail.com> wrote in message Show quoteHide quote news:1150121845.313400.43670@h76g2000cwa.googlegroups.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 >
GridView override InitializePager columnSpan problem when using BoundField Visible=false
back to calling page Page / UserControl OnInit Problem Copying A Control Not As A Reference Where is Page.RegisterClientScriptBlock Available? sorting in a datagrid how to raise SelectedIndexChange event? Determining item count of databound DropDownList checkbox weird Problem Control in template does not bubble events |
|||||||||||||||||||||||