Search code examples
c#asp.netascxwebusercontrolmojoportal

Web User Control Hide elements after submit


I have a web user control displayed through mojoportal. I have an if condition that checks for IsPostback and hides elements accordingly. I also have an Updatepanel which displays or hides a checkbox according to the selected value of the RadiobuttonList

Now the problem is when i use the updatepanel I have to disable the IsPostback otherwise i'm getting an exception

Invalid postback or callback argument. Event validation is enabled using in configuration or <%@ Page EnableEventValidation="true" %> in a page. 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.

How can i accomplish this? I need to hide the elements after the form is submitted or loaded the first time.


Solution

  • 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:

    <%@ 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)