问题
I want to embed Windows Media Player into my ASP.NET page. I do it with this code, which works fine:
<OBJECT id='mediaPlayer1' width="180" height="50"
classid='CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95'
codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701'
standby='Loading Microsoft Windows Media Player components...' type='application/x-oleobject'>
<param name='fileName' value="http..">
<param name='animationatStart' value='true'>
<param name='transparentatStart' value='true'>
<param name='autoStart' value="false">
<param name='showControls' value="true">
<param name ="ShowAudioControls"value="true">
<param name="ShowStatusBar" value="true">
<param name='loop' value="false">
<EMBED type='application/x-mplayer2'
pluginspage='http://microsoft.com/windows/mediaplayer/en/download/'
id='mediaPlayer' name='mediaPlayer' displaysize='4' autosize='-1'
bgcolor='darkblue' showcontrols="true" showtracker='-1'
showdisplay='0' showstatusbar='-1' videoborder3d='-1' width="420" height="380"
src="http..."
autostart="true" designtimesp='5311' loop="false">
</EMBED>
</OBJECT>
My problem is, that I want to change the url in my code behind, (like here but it is in VB, not C#) because I load the Urls out of a database. So is there a way, where I can add this code in my c# part or -even better- to access the url from the c# part?
Sorry if this is a stupid question, but I searched for hours now.. and this.FindControl(mediaPlayer1); doesnt work.
回答1:
Override the Render
method.
Edit it to suite your requirements.
protected override void Render(HtmlTextWriter writer)
{
StringBuilder stringBuilder = new StringBuilder("<OBJECT "
+"ID='" +this.ClientID + "' "
+ "name='" + this.ClientID + "' "
+"CLASSID='CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6'"
+"VIEWASTEXT"
);
stringBuilder.Append("<PARAM name='autostart' value='false'>");
stringBuilder.Append("<PARAM name='autoplay' value='false'>");
stringBuilder.Append("<PARAM name='URL' value='/" + fileUrl + "/" + selectedFile + "'>");
stringBuilder.Append("<PARAM name='rate' value='1'>");
stringBuilder.Append("<PARAM name='balance' value='0'>");
stringBuilder.Append("<PARAM name='enabled' value='true'>");
stringBuilder.Append("<PARAM name='enabledContextMenu' value='true'>");
stringBuilder.Append("<PARAM name='fullScreen' value='false'>");
stringBuilder.Append("<PARAM name='playCount' value='1'>");
stringBuilder.Append("<PARAM name='volume' value='100'>");
stringBuilder.Append("</OBJECT>");
divWindowsMediaPlayer.InnerHtml = stringBuilder.ToString();
base.Render(writer);
}
回答2:
Ok, of course there already was an answer I didnt see 4 hours long while searching yesterday, but just this morning.. : Using Object tags in asp.net
来源:https://stackoverflow.com/questions/12843653/adding-object-or-changing-its-parameter-programmatically-in-c-sharp-asp-net