views:

381

answers:

1

I have a ListView on a Page within a MasterPage and some very ugly ugly autogenerated IDs.

Such as..."ctl00_workbenchPlaceHolder_ListView1_ctrl1_LibItem2One"

Using swfobject.embedSWF(...) requires me to hand over the id of a div on my page that can be replaced with object/embed markup depending on the browser context.

My aim is to show the user a collection of video's they have uploaded to their website so they can review them and change some related data if desired.

Hence the ListView which is populated via a SQLDataSource which currently provides a number of URLs pointing to .flv files.

But it ain't gonna work if I put a <div id="replaceme"></div>' in my user control because I may then have more than one id="replaceme" and poor swfobject won't like it.

So my evil solution is to put an <asp:Literal> in my usercontrol and build the script, function name and div tag id as a string.

ApplyVideoConfiguration is called if the library object retreived from the database is a video and switches to the relevant View of a MultiView control.

    protected void ApplyVideoConfiguration()
{
    MultiViewLibItem.ActiveViewIndex = 3;
    string functionName = "MakeFlashFor_" + this.ClientID;
    string divId = "fp" + this.ClientID;
    VideoScriptLiteral.Text =
        "<script type=\"text/javascript\">" +
        "Sys.Application.add_load(" + functionName + ");" + 
        "function " + functionName + "(){" +
        "swfobject.embedSWF('PanamaVideoThumbnail.swf', '" + divId + "', '140', '127', '10');" +
        "};" +

        "</script>" + 
        "<div id=\"" + divId + "\" ></div>" ;
}

I was wondering, just how bad a solution is this, I'm really completely inexperienced when it comes to best practices but my instincts are telling me this is bad, although it does succeed in the aim of embedding some Flash Player instances.

Can anyone help me make it beautiful?

+1  A: 

Um, I've found an improved (and also less embarrassing) solution.

For starters, I read the swfobject2_2 documentation thoroughly.

Decided I should really put more elbow grease into it and actually write some markup!

So I played around with trying to use an <object runat="server"> tag that I could manage from codebehind but discovered ASP.Net helpfully won't let you do that anyway...

The penny finally dropped that I could use inline code to doctor my markup on a per databound ListViewItem basis.

My result:

            <asp:View runat="server" ID="VideoView">
                <% string flashvars = "videourl=../../" + ItemRelativeUri;%>
                <object id="flashplayer" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="110" height="90" name="obout">
                    <param name="movie" value="flash/libview.swf" />
                    <param name="flashvars" value="<% = flashvars %>" />
                    <asp:Literal runat="server" ID="LiteralParamFlashVars" />
                    <!--[if !IE]>-->
                    <object type="application/x-shockwave-flash" 
                    data="flash/libview.swf?<% =flashvars %>"
                     width="110"
                        height="90" name="obin">
                        <!--<![endif]-->
                        <p>
                            You need Flash Player v 10 or better to view this video.</p>
                        <!--[if !IE]>-->
                    </object>
                    <!--<![endif]-->
                </object>
            </asp:View>
panamack
Welldone, you can mark your own answer as the answer to your question to close the loop
Greg B
Good plan, thanks Greg
panamack