How To Access Div, Iframe Html Controls Using code behind

How To Access Div, Iframe Html Controls Using code behind

You want to access div or Iframe Html controls using Asp.net code behind. In Asp.net you can do this by adding extra attribute runat="server" to those elements. Here we will see how to access and control the rendering of div and iframe using asp.net c# and VB.net code.

DIV Runat server Example: let's access Html div control in asp.net code behind.

<div id="topLeader" runat="server">

Access Div at server side using code behind.

protected void Button1_Click(object sender, EventArgs e)
  {
    topLeader.Visible = false;    
  }

Asp.net Iframe Example

It's not a good practice to use Iframe in web applications. But, you may want to access the properties of Iframe or load the pages into Iframe dynamically. Sometimes you want to load the Iframe based on condition and load the website into it accordingly.

You can access the src element of Iframe by making Iframe to run at server side

asp.net iframe src code behind Let's see how to access src of Iframe.



Asp.net code to access src of Iframe
 protected void Button1_Click(object sender, EventArgs e)
  {
    searchEngine.Attributes.Add("src","http://www.bing.com?q=satalaj");
  }

Tags:

Asp.net access html control textbox element value at code behindhtml without using tables tableless html table less html css tableless layoutsAsp.net Create Html ControlsOnline html editor online JavaScript editorC# HtmlTextWriter ExampleAsp.net How to display HTML contentsBasic HTML5 TagsPaypal purpose code IndiaHTML5 With DataBaseRegularExpression remove html tagsHTML5 Tutorial

Author

My name is Satalaj, but people call me Sat. Here is my homepage: . I live in Pune, PN and work as a Software Engineer. I'm former MVP in ASP.net year 2010.
Disclaimer: Views or opinion expressed here are my personal research and it has nothing to do with my employer. You are free to use the code, ideas/hints in your projects. However, you should not copy and paste my original content to other web sites. Feel free to copy or extend the code.
If you want to fight with me, this website is not for you.
 

I'm Satalaj.