visual studio 2008 - Getting asp.net user control to emit SCRIPT block only once if needed -


i'm seeking advice on how best encapsulate html markup , behavior extensive reuse.

i've developed working version of "context sensitive" on given .aspx page uses qtip2 plugin jquery ("squeezed up" here completeness question):

$('a.mymore[title]').qtip({     content: {  title: { button: true } }     , style: { classes: 'qtip-youtube mycustomclass' }     , position: { target: 'mouse',  adjust: { x: 5, y: 5} }     , show: { effect: function() {  $(this).fadeto(500, 1); } }     , events:{hide:function(event, api) {if (event.originalevent.type !== 'click') return false;}} }); 

here sample of the markup operated upon plugin above i'd encapsulate:

<a class="mymore" href="#" title='text here displayed jquery plugin called qtip2'>    <img src='../images/icon/info1.png' alt='?' /> </a> 

this in older environment of visual studio 2008 webforms using vb.net. 1 thread on expressed need - see mvc3 razor views - encapsulation approach can think of writing asp.net web user control (.ascx) dump out html need. envision being able sprinkle throughout .aspx pages:

<qtiph:qtiphelper title="here content qtip." runat="server" /> 

am on right track given "old-ish" environment in have work?

i started in on writing control , noticed there no title attribute of these server controls - <asp:hyperlink nor <asp:imagebutton nor <asp:linkbutton. don't think code-behind of user control can inject title attribute text standard html <a> tag.

i think know need rendered i'm looking advice on best approach. thanks.

edit - update:

so here .ascx file came with:

<%@ control language="vb" autoeventwireup="false"    codebehind="qtiphelper.ascx.vb"   inherits="myprojectname.qtiphelper" %>  <asp:hyperlink id="hyperlink1" runat="server" cssclass="mymore"></asp:hyperlink> 

i discovered "missing" attributes "title" can handled following code-behind adds attributes collection of control:

public partial class qtiphelper inherits system.web.ui.usercontrol public title string = nothing protected sub page_load(byval sender object, byval e system.eventargs) handles me.load if title nothing orelse title = ""         visible = false else     dim encodedtitle string = server.htmlencode(title)     hyperlink1.attributes.add("title", encodedtitle)     hyperlink1.attributes.add("href", "#")     hyperlink1.imageurl = "../images/icon/info1.png" end if end sub end class 

on invoking page(s), added this:

<%@ register  tagprefix="qtip" tagname="qtiphelper" src="~/usercontrols/qtiphelper.ascx" %>  

and spit out html, added this:

<qtip:qtiphelper runat="server" title="grist mill courtesy of qtip" >         </qtip:qtiphelper> 

is there coding technique added user control emit one javascript script block @ bottom of page (assuming 1 or more tags qtiphelper present in html above)?

in retrospect, weird question (i think because never had before)...

anyway, collected current uses of qtip in single javascript file reference @ bottom of each .aspx page uses this:

<script type="text/javascript" src="<%= resolveclienturl("~/js/qtipcode.js") %>"></script> 

so, boils down to:

1. writing single user control  2. registering user control on .aspx content pages need 3. sprinkling .aspx content page user control tag whereever needed 4. adding script tag point qtip javascript file  5. ensuring selectors in jquery "match up" html markup on page  

i hope helps else. have learned alot new stuff trying this.


Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -