I desingned a page with tags, Now I want to access object tags in code behind.
This is aspx page code....
<object type="label" runat="server" class="System.Web.UI.WebControls.Label" id="label_priority" parent="-1" bindedfield="priority" empty="1" value="MyValue">
Here I am adding runat=server
in object tags it is giving error as
"An object tag must contain a Class, ClassID or ProgID attribute."
then I added class="System.Web.UI.WebControls.Label"
, now not giving any error but not showing anything in browser.
so My question is how do I access object tags in aspx.cs page? or I want to create a label with object tag that is accessible in code behind.
Sujeet
When you have runat="server" on a <object/> or <script/> tag, .NET expects it to be a server side object. You can however create the entire markup on the server side. Assuming you have <div id="somecontainer" runat="server"></div>
in your page:
protected void Page_Load(object sender, EventArgs e)
{
HtmlGenericControl myObject = new HtmlGenericControl();
myObject.TagName = "object";
myObject.Attributes.Add("data", "somevideo.mpeg");
Page.FindControl("somecontainer").Controls.Add(myObject);
}
The result is:
<div id="somecontainer"><object data="somevideo.mpeg"></object></div>
You can use the same method to add elements inside the object, for instance <param/> tags.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With