i have master page content one page , in this page i have image button and iframe tage , i want to know how to change the src for iframe when user click the image button in asp.net 2.0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _1838282 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void myImageButton_Click(object sender, ImageClickEventArgs e)
{
myIFrame.Attributes.Remove("src");
myIFrame.Attributes.Add("src", "http://www.asp.net");
}
}
thank you very much i really got understant , but my problom is , the ifram is inside the master page , i have two files one is (masterpage.master) and ( Home.aspx) , the iframe show in home.aspx , how to send src where it comes from image button to iframe
?? thanks again :-)
In your ImageButton Click Event you have to do a FindControl to access the IFrame on the Masterpage and then set its value.To do this add this to your aspx page
HtmlControl iFrame = (HtmlControl)Master.FindControl("myIFrame");//Note:Use view source to get the right ID
if(iFrame != null)
iFrame.Attributes["src"] = "www.google.com";
*** If this post helps you, then Mark this post as Answer ***
thank you very much for reply , but really not work , i try in debug mode the iframe condtion is ignore !!! , i really need help my friends , this myhome work i must deilver tommorw !!! :-(
mycousin4eve...
Member
26 Points
56 Posts
how to change the src attribute in iframe
Aug 28, 2012 07:24 PM|LINK
i have master page content one page , in this page i have image button and iframe tage , i want to know how to change the src for iframe when user click the image button in asp.net 2.0
Iframe csharp
joshj
Contributor
3151 Points
545 Posts
Re: how to change the src attribute in iframe
Aug 28, 2012 07:33 PM|LINK
.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="1838282.aspx.cs" Inherits="_1838282" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:ImageButton ID="myImageButton" runat="server" ImageUrl="images/myImage.jpg" onclick="myImageButton_Click" /> <br /> <iframe id="myIFrame" runat="server" src="http://www.google.com"></iframe> </div> </form> </body> </html>.cs
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _1838282 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void myImageButton_Click(object sender, ImageClickEventArgs e) { myIFrame.Attributes.Remove("src"); myIFrame.Attributes.Add("src", "http://www.asp.net"); } }Iframe csharp
inquisitive_...
Contributor
3421 Points
575 Posts
Re: how to change the src attribute in iframe
Aug 28, 2012 07:37 PM|LINK
Add a runat=server and id=myIFrame properties to the iframe and then in the image button click event
while(1)
mycousin4eve...
Member
26 Points
56 Posts
Re: how to change the src attribute in iframe
Aug 28, 2012 08:06 PM|LINK
thank you very much i really got understant , but my problom is , the ifram is inside the master page , i have two files one is (masterpage.master) and ( Home.aspx) , the iframe show in home.aspx , how to send src where it comes from image button to iframe ?? thanks again :-)
inquisitive_...
Contributor
3421 Points
575 Posts
Re: how to change the src attribute in iframe
Aug 28, 2012 08:58 PM|LINK
In your ImageButton Click Event you have to do a FindControl to access the IFrame on the Masterpage and then set its value.To do this add this to your aspx page
Then in the ImageButton_Click event
HtmlControl iFrame = (HtmlControl)Master.FindControl("myIFrame");//Note:Use view source to get the right ID if(iFrame != null) iFrame.Attributes["src"] = "www.google.com";while(1)
joshj
Contributor
3151 Points
545 Posts
Re: how to change the src attribute in iframe
Aug 28, 2012 09:07 PM|LINK
You should get extra points just for understanding that.
mycousin4eve...
Member
26 Points
56 Posts
Re: how to change the src attribute in iframe
Aug 28, 2012 10:51 PM|LINK
thank you very much for reply , but really not work , i try in debug mode the iframe condtion is ignore !!! , i really need help my friends , this myhome work i must deilver tommorw !!! :-(
oned_gk
All-Star
31017 Points
6352 Posts
Re: how to change the src attribute in iframe
Aug 29, 2012 01:50 AM|LINK
try this
Dim ifrm As HtmlControl = CType(Master.FindControl("iframe1"), HtmlControl) ifrm.Attributes("src") = "www.google.com"or
ifrm.Attributes.Item("src") = "www.google.com"
oned_gk
All-Star
31017 Points
6352 Posts
Re: how to change the src attribute in iframe
Aug 29, 2012 02:07 AM|LINK
you can change the iframe value directly in master page page_load event using session (every postback)
iframe1..Attributes("src") = session("iframeurl")when button click
session("iframeurl") = "mypage.aspx"mycousin4eve...
Member
26 Points
56 Posts
Re: how to change the src attribute in iframe
Aug 29, 2012 06:55 AM|LINK
i really thank my friend ( oned_gk ) :-)
this was the answer
in page_Load event in master page :-)
ifrm.Attributes("src") = "www.google.com";