How to access object tags on aspx.cs page?

I created a page with tags, Now I want to access the tags of the objects in the code behind.

This is the 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 add runat=server in the object tags, which gives an error like

 "An object tag must contain a Class, ClassID or ProgID attribute." 

then I added class="System.Web.UI.WebControls.Label" , now not displaying any errors, but not displaying anything in the browser.

so my question is: how to access object tags on aspx.cs page? or I want to create a shortcut with an object tag available in the code.

Sujeet

+4
source share
3 answers

If you have runat = "server" on <object /> or <script />, .NET expects it to be an object on the server side. However, you can create all the markup on the server side. Assuming your page has <div id="somecontainer" runat="server"></div> :

 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); } 

Result:

 <div id="somecontainer"><object data="somevideo.mpeg"></object></div> 

You can use the same method to add elements inside an object, for example, <param /> tags.

+4
source

You can use below, as the code in the page load event, if you want to access this when the page loads:

 ScriptManager.RegisterStartupScript(Page,Page.GetType(), "Script", "document.getElementById('DIVID').style.display='none'",true); 

Here we change the display property of the div. You can change according to your requirements.

Hope this helps you.

0
source

you can do something like this

 <object id="items" class = "System.Collections.ArrayList" runat="server"> 

since it runs on the server now, you can access the code in

0
source

Source: https://habr.com/ru/post/1341971/


All Articles