Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using a variable for value section in object tag

Status
Not open for further replies.

k1Ll5w1tcH

Programmer
Jul 29, 2008
9
ZA
Hi All

I was wondering if anyone could help.
I'm sure the answer is quite simple, but I'm being a n00b today :)

I'd like to populate the value section of an object tag, depending on the value passed in my url, e.g:

.../Default.aspx?P1=whatever

<object id="obj" width="100%" height="100%"
<param name="src" value="<%Request.QueryString["P1"]%>">
</object>

Thanks guys,
Garrith
 
You can do it from CodeBehind, here is what ive done...

Code:
<object id="SiteFlash" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="[URL unfurl="true"]http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0"[/URL]
    width="760" height="269">
    <param id="flashMovieParam" runat="server" name="movie" value="main_navigation.swf" />
    <param name="quality" value="high" />
    <embed id="embedMovieParam" runat="server" quality="high" pluginspage="[URL unfurl="true"]http://www.macromedia.com/go/getflashplayer"[/URL]
        type="application/x-shockwave-flash" width="760" height="269" src="main_navigation.swf"></embed>
</object>


Code:
...
if (!IsPostBack)
{
    flashMovieParam.Attributes.Add("value", FlashMovie);
    embedMovieParam.Attributes.Add("src", FlashMovie);
...

//made up this part for you to handle nulls in the querystring
    public string FlashMovie
    {
        get 
        { return (Request.QueryString["P1"] == null) ? "defaultMovie.swf" : Request.QueryString["P1"]; }
    }
 
Code:
<object id="obj" width="100%" height="100%"     
    <param name="src" value=[COLOR=red]'[/color]<%[COLOR=red]=[/color]Request.QueryString["P1"]%>[COLOR=red]'[/color]>
</object>
I would take this 1 step further and hide the details of where P1 comes from by making a protected readonly property in the code behind.
Code:
<object id="obj" width="100%" height="100%"     
    <param name="src" value='<%=DescriptivePropertyName%>'>
</object>
Code:
protected string DescriptivePropertyName
{
   get { return Request.QueryString["P1"]; }
}

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top