Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Dynamically rendering the content of script

Reply
Thread Tools

Dynamically rendering the content of script

 
 
Yama
Guest
Posts: n/a
 
      10-21-2005
Hi,

How can I dynamically embed the content of a filename.js into a .aspx page
before rendering it to the client?

Thanks,

~yamazed


 
Reply With Quote
 
 
 
 
S. Justin Gengo
Guest
Posts: n/a
 
      10-21-2005
Yama,

Insert the javascript using Page.RegisterStartupScript. Here's an example:

If Not page.IsStartupScriptRegistered("TextBoxFocus") Then
Dim StringBuilder As New System.Text.StringBuilder

With StringBuilder
.Append("<script language=""javascript"">" & vbCrLf)
.Append(vbTab & "<!--" & vbCrLf)
.Append(vbTab & vbTab & "document.getElementById('" &
webControl.ClientID & "').focus();" & vbCrLf)
.Append(vbTab & "//-->" & vbCrLf)
.Append("</script>" & vbCrLf)
End With

page.RegisterStartupScript("TextBoxFocus", StringBuilder.ToString)
End If

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Yama" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> How can I dynamically embed the content of a filename.js into a .aspx
> page before rendering it to the client?
>
> Thanks,
>
> ~yamazed
>



 
Reply With Quote
 
 
 
 
Yama
Guest
Posts: n/a
 
      10-21-2005
Hi,

My javascript has over 3000 lines of code and this will not be practical.
Anything other way?

Thanks,

Yama




"S. Justin Gengo" <justin@[no_spam_please]aboutfortunate.com> wrote in
message news:(E-Mail Removed)...
> Yama,
>
> Insert the javascript using Page.RegisterStartupScript. Here's an example:
>
> If Not page.IsStartupScriptRegistered("TextBoxFocus") Then
> Dim StringBuilder As New System.Text.StringBuilder
>
> With StringBuilder
> .Append("<script language=""javascript"">" & vbCrLf)
> .Append(vbTab & "<!--" & vbCrLf)
> .Append(vbTab & vbTab & "document.getElementById('" &
> webControl.ClientID & "').focus();" & vbCrLf)
> .Append(vbTab & "//-->" & vbCrLf)
> .Append("</script>" & vbCrLf)
> End With
>
> page.RegisterStartupScript("TextBoxFocus", StringBuilder.ToString)
> End If
>
> --
> Sincerely,
>
> S. Justin Gengo, MCP
> Web Developer / Programmer
>
> www.aboutfortunate.com
>
> "Out of chaos comes order."
> Nietzsche
> "Yama" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Hi,
>>
>> How can I dynamically embed the content of a filename.js into a .aspx
>> page before rendering it to the client?
>>
>> Thanks,
>>
>> ~yamazed
>>

>
>



 
Reply With Quote
 
Bruce Barker
Guest
Posts: n/a
 
      10-21-2005
read the file into string, then write it out as explained. you'd be better
off using having the browser fetch it because then it would be cached. 3000
lines is a large payload.

-- bruce (sqlwork.com)




"Yama" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Hi,
>
> My javascript has over 3000 lines of code and this will not be practical.
> Anything other way?
>
> Thanks,
>
> Yama
>
>
>
>
> "S. Justin Gengo" <justin@[no_spam_please]aboutfortunate.com> wrote in
> message news:(E-Mail Removed)...
>> Yama,
>>
>> Insert the javascript using Page.RegisterStartupScript. Here's an
>> example:
>>
>> If Not page.IsStartupScriptRegistered("TextBoxFocus") Then
>> Dim StringBuilder As New System.Text.StringBuilder
>>
>> With StringBuilder
>> .Append("<script language=""javascript"">" & vbCrLf)
>> .Append(vbTab & "<!--" & vbCrLf)
>> .Append(vbTab & vbTab & "document.getElementById('" &
>> webControl.ClientID & "').focus();" & vbCrLf)
>> .Append(vbTab & "//-->" & vbCrLf)
>> .Append("</script>" & vbCrLf)
>> End With
>>
>> page.RegisterStartupScript("TextBoxFocus", StringBuilder.ToString)
>> End If
>>
>> --
>> Sincerely,
>>
>> S. Justin Gengo, MCP
>> Web Developer / Programmer
>>
>> www.aboutfortunate.com
>>
>> "Out of chaos comes order."
>> Nietzsche
>> "Yama" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> Hi,
>>>
>>> How can I dynamically embed the content of a filename.js into a .aspx
>>> page before rendering it to the client?
>>>
>>> Thanks,
>>>
>>> ~yamazed
>>>

>>
>>

>
>



 
Reply With Quote
 
Ken Varn
Guest
Posts: n/a
 
      10-21-2005
See my codeproject article at

http://www.codeproject.com/aspnet/Dy...tRendering.asp

There is a class in the project called EmbeddedJScript. It basically wraps
a bunch of .NET functions that allow you to embed a JavaScript file as a
resource and then dynamically render it to the page.

--
-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.

EmailID = varnk
Domain = Diebold.com
-----------------------------------
"Yama" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> How can I dynamically embed the content of a filename.js into a .aspx

page
> before rendering it to the client?
>
> Thanks,
>
> ~yamazed
>
>



 
Reply With Quote
 
Yama
Guest
Posts: n/a
 
      10-22-2005
Hi Bruce,

I came up with a better solution:

First I detect the browser and what type of scripting I'll use. I compile
each IE6javascript.js (and all others) into the project as an embedded
resource (select the script's property and change the "Build Action" from
"Content to Embedded Resource) then in my code:

Partial Code:
System.Reflection.Assembly _Assembly = this.GetType().Assembly;

using( System.IO.Stream stream = _Assembly.GetManifestResourceStream(
"myAssemby.MyNamespace.MyScriptFolder.IE6javascrip t.js" ) )

{

using( System.IO.StreamReader reader = new System.IO.StreamReader(stream) )

{

string _script = reader.ReadToEnd();

Page.RegisterClientScriptBlock( "KeyReferrerNotUSED", _script );

}

Finally perform a cache on server and client side. If the server code
changes then force the change in the client machine.Hint: I use the Observer
design pattern along with the factory method design pattern to achieve all
of this.

Cheers,



~yamazed







"Bruce Barker" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> read the file into string, then write it out as explained. you'd be better
> off using having the browser fetch it because then it would be cached.
> 3000 lines is a large payload.
>
> -- bruce (sqlwork.com)
>
>
>
>
> "Yama" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> Hi,
>>
>> My javascript has over 3000 lines of code and this will not be practical.
>> Anything other way?
>>
>> Thanks,
>>
>> Yama
>>
>>
>>
>>
>> "S. Justin Gengo" <justin@[no_spam_please]aboutfortunate.com> wrote in
>> message news:(E-Mail Removed)...
>>> Yama,
>>>
>>> Insert the javascript using Page.RegisterStartupScript. Here's an
>>> example:
>>>
>>> If Not page.IsStartupScriptRegistered("TextBoxFocus") Then
>>> Dim StringBuilder As New System.Text.StringBuilder
>>>
>>> With StringBuilder
>>> .Append("<script language=""javascript"">" & vbCrLf)
>>> .Append(vbTab & "<!--" & vbCrLf)
>>> .Append(vbTab & vbTab & "document.getElementById('" &
>>> webControl.ClientID & "').focus();" & vbCrLf)
>>> .Append(vbTab & "//-->" & vbCrLf)
>>> .Append("</script>" & vbCrLf)
>>> End With
>>>
>>> page.RegisterStartupScript("TextBoxFocus", StringBuilder.ToString)
>>> End If
>>>
>>> --
>>> Sincerely,
>>>
>>> S. Justin Gengo, MCP
>>> Web Developer / Programmer
>>>
>>> www.aboutfortunate.com
>>>
>>> "Out of chaos comes order."
>>> Nietzsche
>>> "Yama" <(E-Mail Removed)> wrote in message
>>> news:(E-Mail Removed)...
>>>> Hi,
>>>>
>>>> How can I dynamically embed the content of a filename.js into a .aspx
>>>> page before rendering it to the client?
>>>>
>>>> Thanks,
>>>>
>>>> ~yamazed
>>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
Yama
Guest
Posts: n/a
 
      10-22-2005
Hey Ken,

Not stupid hey! Using the httpModules sounds like an excellent way to handle
caching of the script.

Thanks,

~yamazed




"Ken Varn" <nospam> wrote in message
news:%23n%(E-Mail Removed)...
> See my codeproject article at
>
> http://www.codeproject.com/aspnet/Dy...tRendering.asp
>
> There is a class in the project called EmbeddedJScript. It basically
> wraps
> a bunch of .NET functions that allow you to embed a JavaScript file as a
> resource and then dynamically render it to the page.
>
> --
> -----------------------------------
> Ken Varn
> Senior Software Engineer
> Diebold Inc.
>
> EmailID = varnk
> Domain = Diebold.com
> -----------------------------------
> "Yama" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Hi,
>>
>> How can I dynamically embed the content of a filename.js into a .aspx

> page
>> before rendering it to the client?
>>
>> Thanks,
>>
>> ~yamazed
>>
>>

>
>



 
Reply With Quote
 
Yama
Guest
Posts: n/a
 
      10-22-2005
Hey Ken,

I am going to grab some of ya code dude... And I thought I was a smarty
one! LOL I love your handler.

Thanks for sharing (my blogger will soon be up)

~yamazed


"Ken Varn" <nospam> wrote in message
news:%23n%(E-Mail Removed)...
> See my codeproject article at
>
> http://www.codeproject.com/aspnet/Dy...tRendering.asp
>
> There is a class in the project called EmbeddedJScript. It basically
> wraps
> a bunch of .NET functions that allow you to embed a JavaScript file as a
> resource and then dynamically render it to the page.
>
> --
> -----------------------------------
> Ken Varn
> Senior Software Engineer
> Diebold Inc.
>
> EmailID = varnk
> Domain = Diebold.com
> -----------------------------------
> "Yama" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Hi,
>>
>> How can I dynamically embed the content of a filename.js into a .aspx

> page
>> before rendering it to the client?
>>
>> Thanks,
>>
>> ~yamazed
>>
>>

>
>



 
Reply With Quote
 
Yama
Guest
Posts: n/a
 
      10-22-2005
Hi Ken,

Everything is working fine for me; however, I cannot figure out a way to
cache the javascript it seems like on every page refresh it reads from the
javascript file. Any ideas how to cache it?

Thanks,

Yama



"Ken Varn" <nospam> wrote in message
news:%23n%(E-Mail Removed)...
> See my codeproject article at
>
> http://www.codeproject.com/aspnet/Dy...tRendering.asp
>
> There is a class in the project called EmbeddedJScript. It basically
> wraps
> a bunch of .NET functions that allow you to embed a JavaScript file as a
> resource and then dynamically render it to the page.
>
> --
> -----------------------------------
> Ken Varn
> Senior Software Engineer
> Diebold Inc.
>
> EmailID = varnk
> Domain = Diebold.com
> -----------------------------------
> "Yama" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Hi,
>>
>> How can I dynamically embed the content of a filename.js into a .aspx

> page
>> before rendering it to the client?
>>
>> Thanks,
>>
>> ~yamazed
>>
>>

>
>



 
Reply With Quote
 
Ken Varn
Guest
Posts: n/a
 
      10-28-2005
There may be one other way that I have been trying. I have made some
modifications to the code that I published on CodeProject, but I have not
re-submitted it yet. I basically substituted the HttpModule with an
HttpHandler instead. The Handler then can recall the custom data from
server memory without having to re-load it on each postback. The event
handlers are stored in session state, so they do not have to be destroyed on
each postback as it is done on the current implementation. So far I have
only done it on the CustomImage controls, but I don't see why it couldn't be
done on the JavaScript custom handler as well. If you want the source I can
send it to you.


--
-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.

EmailID = varnk
Domain = Diebold.com
-----------------------------------
"Yama" <(E-Mail Removed)> wrote in message
news:Ozj%(E-Mail Removed)...
> Hi Ken,
>
> Everything is working fine for me; however, I cannot figure out a way to
> cache the javascript it seems like on every page refresh it reads from the
> javascript file. Any ideas how to cache it?
>
> Thanks,
>
> Yama
>
>
>
> "Ken Varn" <nospam> wrote in message
> news:%23n%(E-Mail Removed)...
> > See my codeproject article at
> >
> > http://www.codeproject.com/aspnet/Dy...tRendering.asp
> >
> > There is a class in the project called EmbeddedJScript. It basically
> > wraps
> > a bunch of .NET functions that allow you to embed a JavaScript file as a
> > resource and then dynamically render it to the page.
> >
> > --
> > -----------------------------------
> > Ken Varn
> > Senior Software Engineer
> > Diebold Inc.
> >
> > EmailID = varnk
> > Domain = Diebold.com
> > -----------------------------------
> > "Yama" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> >> Hi,
> >>
> >> How can I dynamically embed the content of a filename.js into a .aspx

> > page
> >> before rendering it to the client?
> >>
> >> Thanks,
> >>
> >> ~yamazed
> >>
> >>

> >
> >

>
>



 
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
error: Only Content controls are allowed directly in a content page that contains Content controls. hazz ASP .Net 6 06-09-2010 01:54 PM
Content Not Rendering in Master Page =?Utf-8?B?R1RC?= ASP .Net 1 09-27-2006 06:59 PM
IE6 SP1 rendering vs IE6 SP2 rendering Peter Mount HTML 4 01-31-2006 08:01 AM
Altering page content prior to rendering page on browser Rob Heckart ASP .Net 6 11-26-2003 12:36 PM
Dynamic HttpTableRow not rendering cell content... David Whitney ASP .Net 3 07-17-2003 08:54 PM



Advertisments