aspx 文件中的服务器端代码

发布于 2024-07-11 01:24:13 字数 771 浏览 10 评论 0原文

我想问一下“用aspx文件编写的服务器端代码”是在控制执行生命周期的哪个阶段执行的?

是在SaveState之前还是之后,我声称它处于渲染阶段,是真的吗?

在 aspx 文件中,如果我的代码写为

“<%”,则

if(true)
{
rdlistAnswers.Items.Clear();
foreach (string item in myCollection)
{
    i.Value = item;
    i.Text = item;
    rdlistAnswers.Items.Add(i);
}
"%>"
<asp:RadioButtonList ID="rdlistAnswers" runat="server"</asp:RadioButtonList>

对所做的更改将呈现但不会保存。 但是当将标记编写为

<asp:RadioButtonList ID="rdlistAnswers" runat="server" OnPreRender="loadMe"</asp:RadioButtonList>

-as loadMe 是 aspx.cs 文件中的事件处理程序方法时,会产生与上面的代码相同的效果 - 更改会被渲染并保存,因此当我在 PreRender 阶段进行更改时,状态会被保存,但是当我通过将逻辑放置在不保存的 aspx 文件中来做到这一点,这意味着 - 至少正如我所说 - 放置在 aspx 文件中的服务器端代码在渲染阶段执行,你同意我吗???

I want to ask in which phase of Control Execution Lifecycle is the "Server-Side-Code written in aspx file" being executed?

Is it before SaveState or after, I claim it's in the rendering phase, is it true??

in aspx file if my code writen as

"<%"

if(true)
{
rdlistAnswers.Items.Clear();
foreach (string item in myCollection)
{
    i.Value = item;
    i.Text = item;
    rdlistAnswers.Items.Add(i);
}
"%>"
<asp:RadioButtonList ID="rdlistAnswers" runat="server"</asp:RadioButtonList>

the changes made to the are rendered but not saved.
but when write the tag as

<asp:RadioButtonList ID="rdlistAnswers" runat="server" OnPreRender="loadMe"</asp:RadioButtonList>

-as loadMe is an event handler method in the aspx.cs file makes the same thing as code above- the changes are rendered and saved, so when I do changes in PreRender phase the state is saved but when I do it by placing the logic in the aspx file its not saved, this means -at least as I claim- that server-side code placed in aspx file executes in rendering phase, do you agree me???

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我不吻晚风 2024-07-18 01:24:13

Code written directly inside the aspx file will be executed at the end of Render Control in the ASP.NET page lifecycle.

I tested it precompiling an aspx file and using Reflector to look at the decompiled code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文