简体   繁体   English

如何将变量从C#类输出到aspx文件(asp.net)

[英]How can I output variable from C# class to aspx file (asp.net)

I'm unable to output variable from code behind to aspx file. 我无法将变量从代码后面输出到aspx文件。 Please help me out, I'll be thankful. 请帮帮我,我会很感激。 Here is code of aspx.cs and aspx files: 这是aspx.cs和aspx文件的代码:

protected void Page_Load(object sender, EventArgs e)
{
    String Marks = (String) (Session["Marks"]);                
}

Here is code of aspx file: 这是aspx文件的代码:

<!DOCTYPE html>    
<html xmlns="http://www.w3.org/1999/xhtml">
  <head runat="server">
    <title></title>
  </head>
  <body>
    <form id="form1" runat="server">
      <div>            
        <h1> <%=Marks%> </h1>            
      </div>
    </form>
  </body>
</html>

使用以下代码段

<h1><% =Session["Marks"]%></h1> 

You can't access variables from the code behind. 您不能从后面的代码访问变量。 However you can access session in aspx page. 但是,您可以在aspx页面中访问会话。 So use Session["Marks"] 因此,请使用Session["Marks"]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 C# asp.net 后端(.aspx.cs 文件)中的类(.cs)调用变量 - How to call variables from a class(.cs) in C# asp.net backend (.aspx.cs file) 如何从usercontrol调用aspx内容页面方法? ASP.NET,C# - How can I call aspx content page methods from usercontrol? ASP.NET, C# 如何从asp.net c#中的url中删除“.aspx”? - How to remove “.aspx” from url in asp.net c#? 如何在asp.net c#的aspx.cs页面中访问td ID? - How can I access td Id in aspx.cs page of asp.net c#? 如何在asp.net中将变量值从aspx.cs文件设置为aspx文件? - how to set variable value from aspx.cs file to aspx file in asp.net? 如何从ASP.NET MVC网站中生成可下载的c#类? - How can I generate a downloadable c# class from within an ASP.NET MVC website? 从asp.net c#中的类访问单击事件和aspx页面的控制 - access click event and control of aspx page from class in asp.net c# 在C#ASP.NET,MVC中,如何从INSIDE输出任意文本? - How does one output arbitrary text from INSIDE a control class in C# ASP.NET, MVC? 如何根据从下拉列表中选择的内容(ASP.NET中的C#)更改标签的输出 - How can I change the output of a label, based on what's selected from a dropdown list (C# in ASP.NET) 如何在C#类(.cs文件)和ASP.NET .aspx文件中使用相同的OracleMembershipProvider? - How can you use the same OracleMembershipProvider in C# classes (.cs files) AND ASP.NET .aspx files?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM