0

Page_Unload 事件是否有可能重置 textbox.text?我发现不能!

标记

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:TextBox ID="txt" runat="server"></asp:TextBox>
    <asp:Button ID="btn" runat="server" Text="Do something1" />
    <asp:Button ID="btn1" runat="server" Text="Do something2" />
    <asp:Button ID="btn2" runat="server" Text="Do something3" />
    </div>
    </form>
</body>
</html>

背后的代码

Protected Sub btn_Click(sender As Object, e As System.EventArgs) Handles btn.Click
    Method1()
End Sub

Protected Sub btn1_Click(sender As Object, e As System.EventArgs) Handles btn1.Click
    Method2()
End Sub

Protected Sub btn2_Click(sender As Object, e As System.EventArgs) Handles btn2.Click
    Method3()
End Sub

Private Sub Method1()
    'Do something
End Sub

Private Sub Method2()
    'Do something
End Sub

Private Sub Method3()
    'Do something
End Sub

Protected Sub Page_Unload(sender As Object, e As System.EventArgs) Handles Me.Unload
    txt.Text = String.Empty
End Sub

你可能认为把txt.Text = String.Emptyin each 方法放入是解决这个问题的最好方法,但是如果我有 80 个按钮,那么我必须放入txt.Text = String.Empty80 个按钮的点击事件。有没有更好的方法来做到这一点?

4

1 回答 1

0

查看asp.net 页面的生命周期

在所有按钮单击后调用的事件是 PreRender。

您可以覆盖 OnPreRender 以清除此类文本。

页面生命周期

于 2012-08-03T04:10:34.317 回答