Reputation: 853
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)
}
Upvotes: 0
Views: 5073
Reputation: 31383
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%>
Upvotes: 2
Reputation: 399
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.
Upvotes: 0