How can I access an IFRAME from the codebehind file in ASP.NET?

后端 未结 10 1660
隐瞒了意图╮
隐瞒了意图╮ 2020-12-14 07:09

I am trying to set attributes for an IFRAME html control from the code-behind aspx.cs file.

I came across a post that says you can use FindControl to find the non-as

相关标签:
10条回答
  • 2020-12-14 07:42

    Try this.

    ContentPlaceHolder cplHolder = (ContentPlaceHolder)this.CurrentMaster.FindControl("contentMain");

    HtmlControl cpanel= (HtmlControl)cplHolder.FindControl("contentPanel1");

    0 讨论(0)
  • 2020-12-14 07:43

    If the iframe is directly on the page where the code is running, you should be able to reference it directly:

    
    contentPanel1.Attribute = value;
    

    If not (it's in a child control, or the MasterPage), you'll need a good idea of the hierarchy of the page... Or use the brute-force method of writing a recursive version of FindControl().

    0 讨论(0)
  • 2020-12-14 07:48

    aspx page

    <iframe id="fblikes" runat="server"></iframe>
    

    Code behind

    this.fblikes.Attributes["src"] = "/productdetails/fblike.ashx";

    Very simple....

    0 讨论(0)
  • 2020-12-14 07:50

    This works for me.

    ASPX :

    <iframe id="ContentIframe" runat="server"></iframe>
    

    I can access the iframe directly via id.

    Code Behind :

    ContentIframe.Attributes["src"] = "stackoverflow.com";
    
    0 讨论(0)
提交回复
热议问题