How to use iframe source through codebehind in asp.net 2.0

Last post 04-21-2008 11:30 PM by Hong-Gang Chen - MSFT. 1 replies.

Sort Posts:

  • How to use iframe source through codebehind in asp.net 2.0

    04-17-2008, 10:32 AM
    • Member
      27 point Member
    • Sandya81
    • Member since 04-10-2008, 9:42 AM
    • Posts 46

    My code is :

    protected System.Web.UI.HtmlControls.HtmlGenericControl frame1;protected void Page_Load(object sender, EventArgs e)

    {

    string selectedLanguage = Convert.ToString(Session["selectedLanguage"]);

    UICulture = selectedLanguage;

    Culture = selectedLanguage;

    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(selectedLanguage);

    Thread.CurrentThread.CurrentUICulture = new CultureInfo(selectedLanguage);

    string strResourcesPath = Server.MapPath("App_LocalResources");

    ResourceManager rm = ResourceManager.CreateFileBasedResourceManager("resource", strResourcesPath, null);

    HtmlControl frame1 = (HtmlControl)this.FindControl("region1");frame1.Attributes["src"] = rm.GetString("022").ToString();

     

     

    }

    And iframe is:

    <div id="content2">

    <iframe id="region1" name = "region1" src="regions/Russia.htm" frameborder="0" width="220" scrolling="auto" height="280" runat="server"></iframe>

     

    </div>

    When i try to run i am getting error like Object reference not set to an instance of an object. Iam using localisation in my application.According to the language it should display the page in iframe.Could please tell me whats wrong in the above code.I need it.

     

  • Re: How to use iframe source through codebehind in asp.net 2.0

    04-21-2008, 11:30 PM
    Answer

    Sandya81:
    HtmlControl frame1 = (HtmlControl)this.FindControl("region1");

    Sandya81:
    <iframe id="region1" name = "region1" src="regions/Russia.htm" frameborder="0" width="220" scrolling="auto" height="280" runat="server"></iframe>

    Hi Sandya81,

    Please change above two lines to below two lines to solve your problem:

    HtmlContainerControl frame1 = (HtmlContainerControl)this.FindControl("region1");
    <iframe id="region1" id= "region1" name = "region1" src="regions/Russia.htm" frameborder="0" width="220" scrolling="auto" height="280" runat="server"></iframe>
    Hope it helps,
    Hong Gang

     

    Hong-Gang Chen
    Microsoft Online Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Page 1 of 1 (2 items)