[英]asp.net cs variable in aspx page
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.
我有一个带有iframe的aspx页面,我正试图从我的代码后面传递一个名为'pageId'的变量。 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.
我已经查看了SO和其他网站上的各种示例,并且大多数人向其他人提出了数据绑定问题,并且我已经介绍了一些示例。 Perhaps I can't use a variable like the way Im trying to do in an iframe?
也许我不能像我试图在iframe中那样使用变量?
I've introduced the get/set and public properties, but just a little lost. 我已经介绍了get / set和public属性,但只是有点丢失了。 Anyone help point me in the right diection please?
有人帮我指出正确的饮食吗?
aspx page aspx页面
<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 aspx.cs页面
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)
}
Your private variable and public property have the same name. 您的私有变量和公共属性具有相同的名称。 Try using a capital P in your property name.
尝试在您的媒体资源名称中使用大写字母P. Also don't declare a new variable pageId in Page_Load.
也不要在Page_Load中声明新的变量pageId。 PageId is blank because you are setting the local Page_Load method variable, and not the class level variable.
PageId为空,因为您正在设置本地Page_Load方法变量,而不是类级别变量。
private string pageId;
public string PageId { get {return pageId; } }
protected void Page_Load(object sender, EventArgs e)
{
pageId = 'Y2840';
}
In your aspx page: 在您的aspx页面中:
<%=PageId%>
method 1. 方法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. 方法2。
put iframe in formview and give it a datasource. 把iframe放在formview中并给它一个数据源。 Then use your existing code.
然后使用您现有的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.