Register ViewState for “visible=false” UserControl - ASP.NET

ε祈祈猫儿з 提交于 2019-12-24 18:10:59

问题


We have a web app(-ish) webform, and we use many custom UserControls. We load a bunch of them in each view, but we don't want them to render, or even pre-render, until we don't have to use them. Then we set Visible = False in each control and then we use Update Panels to set it to True whenever the control is needed. The control then shows up correctly.

But in the next postback we have a very nasty MAC validation error, and we think it is related to the ASP not updating the viewstate (but I don't know if that's entirely true yet).

The question: Is it possible to know in exactly wich argument the MAC validation is throwing an error? If we're right, and the ViewState for the user controls is not being updated in the already sent page, what would be the correct way to do it / workaround for it?

Many thanks


回答1:


I've since learnt a lot of ASP, so I will clarify my failure points:

and we think it is related to the ASP not updating the viewstate (but I don't know if that's entirely true yet)

Of course, it's absolutelly false. ASP updates the entire ViewState on every post back, so there's no way to not update it.

The MAC validation issue occured when we turned on the UserControl (Visible=true) because we didn't specify the validation of the events that control performed (performing custom __doPostBack()s)

So, the assumption is entirelly incorrect, and the error goes away by simply registering with RegisterForEventValidation() (see here)



来源:https://stackoverflow.com/questions/27483486/register-viewstate-for-visible-false-usercontrol-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!