gpt4 book ai didi

asp.net - 什么时候禁用 View 状态是安全的?

转载 作者:行者123 更新时间:2023-12-04 17:14:10 26 4
gpt4 key购买 nike

什么时候禁用 View 状态是安全的?适用于哪些控件?在什么情况下?
在用户控件中,我禁用了 View 状态,但是如果我尝试单击此控件

<asp:LinkButton ID="LinkButton1" runat="server" 
CommandName="Delete"
OnClientClick="return confirm('¿Está seguro que desea eliminar el mensaje?');"
EnableViewState="true">
<asp:Image ID="ImageButton1" runat="server" ImageUrl="~/Content/Images/delete.png"
ToolTip="Eliminar mensaje" /> Eliminar
</asp:LinkButton>
我收到 System.InvalidOperationException 异常。它位于 ListView 内。

最佳答案

归结为您是否希望页面在回发中记住内容。如果您在每个回发 View 状态上重新创建或分配值是不必要的

Here's一些好的建议

Dynamically inserted value on the controls (By binding or programmatically assigning) – The values of this controls will not retain when it is rerendered, e.g. Switching from view1 to view2. But you have to consider two things, if you think repopulating the values for every render is to heavy to implement then don’t disable the viewstate, if not then you may disable it and reinitialize your controls on render event. Why am I suggesting this? It’s because processing serverside code is much faster than transferring a large junk of data back to the server and unto the client on roundtrips.

On Datalist and DropDownList – If you are not using the OnSelectedIndex Change event then you may disable the viewstate.

On Gridviews – This is the hardest part to decide whether to disable viewstate or retain it. If you are just displaying data on it or even using it just for selection, then disable the viewstate. If you are using paging, edit or delete functionality then don’t. Gridview has the largest viewstate capacity so you should use it wisely. If you have to update as many as 5 columns then why not just open another view then set the values there to be updated rather than updating it on the gridview directly.

关于asp.net - 什么时候禁用 View 状态是安全的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/861537/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com