And the following back code:
[code]
C#
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("http://www.google.com/search?hl=en&q=" + TextBox1.Text.ToString() + "");
}
[/code]Now i want the back code function runs on the iframe,where the same function runs on the iframe.
Any ideas?
Bryian TanRank #396 · 6.3K reputationPosted Aug 25, 2010, 5:02 AM EDT
try create a new page with the name TestIframe.aspx, paste the below code in it
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestIframe.aspx.cs" Inherits="TestIframe" %>
Then paste the following codes in the TestIframe.aspx.cs file
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class TestIframe : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
iframe1.Attributes.Add("src", "http://www.google.com/search?hl=en&q=" + TextBox1.Text + "");
}
}
Bryian TanRank #396 · 6.3K reputationPosted Aug 24, 2010, 7:21 PM EDT
You can try something like below.
.aspx
.cs
protected void Button1_Click(object sender, EventArgs e)
{
iframe1.Attributes.Add("src", "http://www.google.com/search?hl=en&q=" + TextBox1.Text + "");
}
Bryian TanRank #396 · 6.3K reputationPosted Aug 24, 2010, 9:34 PM EDT
Do you have on your .aspx page?
Sharrangas123 reputationPosted Aug 24, 2010, 11:06 PM EDT
Try this in .cs.
HtmlGenericControl googlesearchiframe = (HtmlGenericControl)Page.Master.FindControl("iframe");
if(googlesearchiframe!=null)
{
googlesearchiframe.Attributes("src") = "http://www.google.com/search?hl=en&q=" + TextBox1.Text + "";
}
sam147 reputationPosted Aug 24, 2010, 7:55 PM EDT
It shows the following error when i use your code;
The name 'iframe1' does not exist in the current context
I even tried the code by opening in new page.
sam147 reputationPosted Aug 24, 2010, 10:08 PM EDT
am i missing some arguments?
or the i frame code should include asp tag?
sam147 reputationPosted Aug 24, 2010, 11:21 PM EDT
sam147 reputationPosted Aug 25, 2010, 4:50 PM EDT
Rupesh Pawar3 reputationPosted Aug 19, 2015, 2:56 AM EDT
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts