日期:2014-05-18  浏览次数:20444 次

ASP.NET前台页面如何调用后台的变量?
如后台有个方法   public   void   selinfo()   前台可以这样写: <%selinfo();%>
如果有一个变量   string   info;,前台该怎么写?

------解决方案--------------------
<%=info %>
------解决方案--------------------
public string info;
<%=info %>


------解决方案--------------------
可以取得

后台
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class test : System.Web.UI.Page
{
protected string aaa;

protected void Page_Load(object sender, EventArgs e)
{
aaa = "123 ";
}
}

前台:
<%@ Page Language= "C# " AutoEventWireup= "true " CodeFile= "test.aspx.cs " Inherits= "test " %>

<!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 id= "Head1 " runat= "server ">
<title> 无标题页 </title>

</head>
<body>
<form id= "form1 " runat= "server ">

<%= aaa %>


</form>
</body>
</html>


已经测试,没问题