0

Need some help please. I've got an aspx page with an iframe and I'm trying to pass a variable called 'pageId' from my code behind to it. I've looked at various examples on SO and other sites and most suggest to others its a databinding issue and I've followed through some of the examples. Perhaps I can't use a variable like the way Im trying to do in an iframe?

I've introduced the get/set and public properties, but just a little lost. Anyone help point me in the right diection please?

aspx page

<iframe width="690" height="600" src="https://myserver.com/Index.php?pageId=<%=pageId%>" frameborder="0" scrolling="yes" style="border-width: 0px;"></iframe> 

aspx.cs page

protected String pageId { get; set; }

//private string pageId;
//public String pageId { get {return pageId; } }

protected void Page_Load(object sender, EventArgs e)
{
    string pageId = 'Y2840'; //this is generated from my db and I know the data is being stored in here as I have Response.Write(pageId)   
}
4
  • What is the error you are encountering? Or what is not happening? Commented Mar 28, 2013 at 16:13
  • Im not hetting an error as such, but myserver.com/Index.php does not display the value of pageId. Its like there is nothing in there, but when I response write there is Commented Mar 28, 2013 at 16:16
  • is the iframe inside a FormView? otherwise might be easier to set an id on the iframe and set the src in code-behind. Commented Mar 28, 2013 at 16:18
  • The iframe is within the standard form tags? I'll look into FormView Commented Mar 28, 2013 at 16:20

2 Answers 2

2

Your private variable and public property have the same name. Try using a capital P in your property name. Also don't declare a new variable pageId in Page_Load. PageId is blank because you are setting the local Page_Load method variable, and not the class level variable.

private string pageId;
public string PageId { get {return pageId; } }

protected void Page_Load(object sender, EventArgs e)
{
    pageId = 'Y2840';  
}

In your aspx page:

<%=PageId%>
Sign up to request clarification or add additional context in comments.

2 Comments

Weird, so did you remove string from the Page_Load method?
If I just add <%=PageId%> to my aspx page the variable is displaying out. However its not passing through to my server in the iframe. I think I'll try the formview method. Ooh So close.
0

method 1.

<iframe runat="server" id="myiframe" width="690" height="600"      
frameborder="0" scrolling="yes"     style="border-width: 0px;"></iframe> 

code-behind:

myiframe.src="https://myserver.com/Index.php?pageId=" + pageId;

method 2.

put iframe in formview and give it a datasource. Then use your existing code.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.