检查 ASP.net 表单中的更改
我想检查我的 ASP.NET 网页上的表单是否有任何更改,我有哪些选择?
我应该检查视图状态是否已更改,或者应该在代码隐藏中创建一个标志,由 Webcontrol 事件(如文本框的 TextChanged 或下拉列表的 SelectedIndexChanged)触发?
I want to check if there have been any changes to a form on my ASP.NET webpage, What are my options?
Should i check if the viewstate has changed or should create a flag in the code-behind, triggered by webcontrol events like TextChanged for Textboxes or SelectedIndexChanged for Dropdownlists?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以将发送的值存储在属性中。类似于:
在回发时,您可以比较:
您必须对表单中的每个控件执行此操作。当然,您可以编写一个过程以更自动的方式执行此操作,例如迭代所有控件。
You could store the sent values in attributes. Something like:
On postback, you can compare:
You would have to do that for every control in your form. Of course, you could write a procedure to do this in a more automatic way, like iterating through all your controls.
简单的方法:提交该表单,然后在服务器端将发送的值与存储在数据层中的值进行比较。
Easy way: submit that form, and at server-side, compare sent values with those stored in your data layer.
为所有控件设置适当的
OnChange
事件(对于某些控件有所不同,即 Droplist:OnSelectedIndexChanged
),以调用单个form_Changed
函数。在该函数中,将全局变量设置为 true。然后在按钮单击处理程序中检查该值。所有“Changed”事件在按钮单击处理程序之前触发。ASPX
ASPX.CS
Set the proper
OnChange
event (different for some controls, i.e. Droplist:OnSelectedIndexChanged
) for all controls to call a singleform_Changed
function. In that function, set a global variable to true. Then in the Button Click Handler, check that value. All "Changed" events trigger before the button Click handler.ASPX
ASPX.CS