简体   繁体   English

Web用户控件提交后隐藏元素

[英]Web User Control Hide elements after submit

I have a web user control displayed through mojoportal. 我有一个通过mojoportal显示的Web用户控件。 I have an if condition that checks for IsPostback and hides elements accordingly. 我有一个if条件,用于检查IsPostback并相应地隐藏元素。 I also have an Updatepanel which displays or hides a checkbox according to the selected value of the RadiobuttonList 我还有一个Updatepanel,它根据RadiobuttonList的选定值显示或隐藏一个复选框。

Now the problem is when i use the updatepanel I have to disable the IsPostback otherwise i'm getting an exception 现在的问题是,当我使用updatepanel时,我必须禁用IsPostback,否则会出现异常

Invalid postback or callback argument. 无效的回发或回调参数。 Event validation is enabled using in configuration or <%@ Page EnableEventValidation="true" %> in a page. 使用配置或页面中的<%@页面EnableEventValidation =“ true”%>启用事件验证。 For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. 为了安全起见,此功能验证回发或回调事件的参数源自最初呈现它们的服务器控件。 If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation. 如果数据有效且预期,请使用ClientScriptManager.RegisterForEventValidation方法以注册回发或回调数据以进行验证。

How can i accomplish this? 我怎样才能做到这一点? I need to hide the elements after the form is submitted or loaded the first time. 第一次提交或加载表单后,我需要隐藏元素。

This occurs when the values in your controls differ between its original state and the post back. 当控件中的值在其原始状态和回发之间有所不同时,就会发生这种情况。 The quick and easy way to remedy this is to add this to your page header: 解决此问题的快速简便的方法是将其添加到页面标题中:

 EnableEventValidation = "False"

IE: IE浏览器:

<%@ Page Language="VB" AutoEventWireup="false" Inherits="myPage" Codebehind="MyPage.aspx.vb" EnableEventValidation="false"  MasterPageFile="~/Site.Master" %>

But this sacrifices security for simplicity. 但这为了简单而牺牲了安全性。 If security is not a concern, this will work. 如果不关心安全性,那么这将起作用。 Other wise, you need to find out which control is causing this an register it for postback, like this: 否则,您需要找出导致该事件注册的控件,例如:

     ScriptManager.GetCurrent(Page).RegisterAsyncPostBackControl(Me.myControl)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM