PC Review


Reply
Thread Tools Rate Thread

Adding scripts to a user control

 
 
Scott M.
Guest
Posts: n/a
 
      13th Sep 2009
You can include script tags in the HEAD as well as the BODY of a web page
and since your user control will wind up being placed inside another's
document's BODY tags, you're all set to just write them.

The only reason (and it is a good one) that script tags are usually placed
in the head section is so that they can be loaded before everything else.
As long as the scripts you'll be referencing don't get caught up in that,
you can just place them in your div tag.

-Scott

"K Viltersten" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> When i design a web user control, i usually
> put everything in a div, like this:
>
> <@ control ...>
> <div> ... </div>
>
> Now, i need to do some tricks with jQuery, which requires me to reference
> some JS-files
> but i'm not sure where to do so.
>
> Usually, i'd put the references in <head> but how do i do that when
> there's no such
> tag (as in the case with user control)?
>
> I tried to simply putting the <head> tag in
> "by brute force" but regrettably, i didn't get the behavior i expected.
>
> --
>
> Regards
> Konrad Viltersten
> --------------------------------
> May all spammers die an agonizing death;
> have no burial places; their souls be
> chased by demons in Gehenna from one room
> to another for all eternity and beyond.



 
Reply With Quote
 
 
 
 
K Viltersten
Guest
Posts: n/a
 
      13th Sep 2009
When i design a web user control, i usually
put everything in a div, like this:

<@ control ...>
<div> ... </div>

Now, i need to do some tricks with jQuery,
which requires me to reference some JS-files
but i'm not sure where to do so.

Usually, i'd put the references in <head>
but how do i do that when there's no such
tag (as in the case with user control)?

I tried to simply putting the <head> tag in
"by brute force" but regrettably, i didn't
get the behavior i expected.

--

Regards
Konrad Viltersten
--------------------------------
May all spammers die an agonizing death;
have no burial places; their souls be
chased by demons in Gehenna from one room
to another for all eternity and beyond.
 
Reply With Quote
 
Sreenivas
Guest
Posts: n/a
 
      14th Sep 2009

Put the script tag in Head section of the Page or MasterPage(if you
use) ;in which you place the web user control.
Yes, scott's answer would suffice

On Sep 14, 12:29*am, "K Viltersten" <t...@viltersten.com> wrote:
> When i design a web user control, i usually
> put everything in a div, like this:
>
> * <@ control ...>
> * <div> ... </div>
>
> Now, i need to do some tricks with jQuery,
> which requires me to reference some JS-files
> but i'm not sure where to do so.
>
> Usually, i'd put the references in <head>
> but how do i do that when there's no such
> tag (as in the case with user control)?
>
> I tried to simply putting the <head> tag in
> "by brute force" but regrettably, i didn't
> get the behavior i expected.
>
> --
>
> Regards
> Konrad Viltersten
> --------------------------------
> May all spammers die an agonizing death;
> have no burial places; their souls be
> chased by demons in Gehenna from one room
> to another for all eternity and beyond.


 
Reply With Quote
 
Scott M.
Guest
Posts: n/a
 
      14th Sep 2009
The OP's script needs to be in the user control, not a specific page.

-Scott

"Sreenivas" <(E-Mail Removed)> wrote in message
news:bd01e237-1fd0-4fe7-93b3-(E-Mail Removed)...

Put the script tag in Head section of the Page or MasterPage(if you
use) ;in which you place the web user control.
Yes, scott's answer would suffice

On Sep 14, 12:29 am, "K Viltersten" <t...@viltersten.com> wrote:
> When i design a web user control, i usually
> put everything in a div, like this:
>
> <@ control ...>
> <div> ... </div>
>
> Now, i need to do some tricks with jQuery,
> which requires me to reference some JS-files
> but i'm not sure where to do so.
>
> Usually, i'd put the references in <head>
> but how do i do that when there's no such
> tag (as in the case with user control)?
>
> I tried to simply putting the <head> tag in
> "by brute force" but regrettably, i didn't
> get the behavior i expected.
>
> --
>
> Regards
> Konrad Viltersten
> --------------------------------
> May all spammers die an agonizing death;
> have no burial places; their souls be
> chased by demons in Gehenna from one room
> to another for all eternity and beyond.



 
Reply With Quote
 
Gregory A. Beamer
Guest
Posts: n/a
 
      14th Sep 2009
"Scott M." <s-(E-Mail Removed)> wrote in news:Ol0yV3TNKHA.508
@TK2MSFTNGP06.phx.gbl:

> The OP's script needs to be in the user control, not a specific page.


The advice is still correct (oe one "coirrect" way), although not
complete. There are two ways to accomplish what Sreenivas has stated:

1. Use one of the register statements (RegisterStartupScript,
RegisterClientSideScript)

2. Programatically add to the head of the page

In addition, if the OP knows which pages need jQuery, he can add the
directive there, even if the control does not emit. This is not very
useful for a commercial control (one he is selling), but works for his
own site (yes, it is sloppier than registering the script). If jQuery is
used throughout the site, setting it up in the master page is also fine.

Peace and Grace,


--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

My vacation and childhood cancer awareness site:
http://www.crazycancertour.com

*******************************************
| Think outside the box! |
*******************************************
 
Reply With Quote
 
Gregory A. Beamer
Guest
Posts: n/a
 
      14th Sep 2009
"K Viltersten" <(E-Mail Removed)> wrote in news:7h4urgF2s65drU1
@mid.individual.net:

> When i design a web user control, i usually
> put everything in a div, like this:
>
> <@ control ...>
> <div> ... </div>
>
> Now, i need to do some tricks with jQuery,
> which requires me to reference some JS-files
> but i'm not sure where to do so.
>
> Usually, i'd put the references in <head>
> but how do i do that when there's no such
> tag (as in the case with user control)?
>
> I tried to simply putting the <head> tag in
> "by brute force" but regrettably, i didn't
> get the behavior i expected.
>


There are two basic options here:

1. Register client side scripts (or startup scripts)
2. include in head of page or master page

The option you choose depends on a few factors. If this is a commercial
control, you are probably better to register the scripts, but leave an
option to turn this off, as a user may already be using jQuery for
something else (as Microsoft is heavily pushing it).

If this is not commercial, you have choices. If jQuery is used
throughout the site, put it in the master page. If only on a few pages,
you can put it in the head section of the page. If the page inherits
from a master page, you can still register in the head if you have a
head content region (the default since 2.0).

Peace and Grace,

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

My vacation and childhood cancer awareness site:
http://www.crazycancertour.com

*******************************************
| Think outside the box! |
*******************************************
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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
adding a user more than one group through user accounts in control panel. gchandrujs via WindowsKB.com Windows XP Security 1 6th Sep 2007 11:42 PM
Adding a web user control to a web control library rsam2011@yahoo.com Microsoft ASP .NET 1 11th Oct 2006 04:22 AM
2.0 Adding Web user Control to DataList Josh Microsoft ASP .NET 0 27th Jun 2006 02:38 PM
Problem in adding template of server side control using client side scripts Lau Lei Cheong Microsoft ASP .NET 1 13th Oct 2004 11:41 AM
Re: adding user control programatically Shailesh Ratadia Microsoft ASP .NET 1 20th May 2004 04:43 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:20 AM.