联C#code VS Page

编程入门 行业动态 更新时间:2024-10-28 02:27:29
本文介绍了联C#code VS Page_Load方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我工作的ASP.NET Web应用程序。结果我有两个文件 - > example.aspx和example.aspx.cs其背后code

我想知道有什么区别将内嵌C#code。在example.aspx顶部

之间

<%    如果(会话[页]!= NULL)    {        //映射会话方法瓦尔形成元素        loadSessionData();    }%GT;

和把code文件example.aspx.cs背后的code

的的Page_Load()方法

保护无效的Page_Load(对象发件人,EventArgs的发送){     如果(会话[页]!= NULL)     {         //映射会话方法瓦尔形成元素         loadSessionData();     }}

根据在哪里我把code中的应用程序的行为在关于会话的数据加载到表单元素不同。

任何帮助将大大AP preciated。

更新:我想通了,为什么不同的地方,我把code表现不同应用。如果我把内联C#的方法调用时在.aspx顶不上回发运行。如果我把C#方法调用中的.aspx.cs code的的Page_Load()方法隐藏文件它不回发上运行。所以,如果我想要把方法在Page_Load方法,但不能在回发运行它,我需要把它包在

如果(!的IsPostBack){    loadSessionData();}

解决方案

我想执行code时,最大的区别是在时刻。当(我认为)执行内联code这是Page_Render之前的Page_Load occurres。

I am working on an ASP.NET Web Application. I have two files -> example.aspx and its code behind example.aspx.cs

I am wondering what the difference is between putting inline C# code at the top of example.aspx

<% if (Session["Page"] != null) { //method that maps session vars to form elements loadSessionData(); } %>

and putting the code in the Page_Load() method of the code behind file example.aspx.cs

protected void Page_Load(object sender, EventArgs e) { if (Session["Page"] != null) { //method that maps session vars to form elements loadSessionData(); } }

Depending where I put the code the application behaves different in regards to loading the session data into the form elements.

Any help on this would be greatly appreciated.

Update: I figured out why depending on where I put the code the application behaved differently. If I put the inline C# method call at the top of the .aspx it does not run on postbacks. If I put the C# method call in the Page_Load() method of the .aspx.cs code behind file it does run on postbacks. So if I want to put the method in the Page_Load method but not run it on postbacks I would need to wrap it in:

if (!IsPostBack) { loadSessionData(); }

解决方案

I would think the biggest difference would be the moment when the code is executed. Page_Load occurres before the Page_Render which is when (I think) inline code is executed.

更多推荐

联C#code VS Page

本文发布于:2023-11-10 15:37:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1575766.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:code   Page

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!