locked
problem with validation control in updatePanel control RRS feed

  • Question

  • User-316651844 posted

    Hi all,

    I am missing a problem with validation control in updatePanel control:

    I want to hide updatepanel control when page load. When click show button then updatepanel  control will show.

    It show when I remove RequiredFieldValidator  control, and don't show when I add RequiredFieldValidator  control in updatepanel. But I want to validate data

    Help me how to does it work?Please.

    my code here:

    default.aspx page:

    <asp:ScriptManager ID="ScriptManager2" EnablePageMethods="true" runat="server"></asp:ScriptManager>

    <asp:UpdatePanel ID="udpTest" runat="server" Visible="False">
        <ContentTemplate>
            Test <asp:Button ID="Button1" runat="server" Text="Button" /><asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
           <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
       </ContentTemplate>
    </asp:UpdatePanel>

    <asp:Button ID="btnShow" CssClass="btn btn-info" runat="server" Text="Show" OnClick="btnDatHang_Click" />

    and code behind default.cs:

    protected void btnShow_Click(object sender, EventArgs e)
    {
         udpTest.Visible = true;
    }

    Monday, December 22, 2014 4:41 AM

Answers

  • User-316651844 posted

    I try with code : 

    <Triggers>
    <asp:PostBackTrigger ControlID="btnShow" />
    </Triggers>

    and web.config

    <appSettings>
    <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
    </appSettings>

    and Successful!.

    Thanks for your idea!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 23, 2014 1:08 AM

All replies

  • User724169276 posted

    why so much effort to toggle the visibility.Enclose the update panel inside a div and toggle the visibility from javascript.

    Monday, December 22, 2014 4:47 AM
  • User1711366110 posted

    hi khangzz,
      As per your case ,I have been shared my suggestion & Code snippet below :
    1. Set your updatepanel as visible "true" & add updatemode property.
        <asp:UpdatePanel ID="udpTest" runat="server" Visible="true" UpdateMode="Conditional" >
    2.Create a panel inside the content template of the update panel.& set it as visible="false"
    3.Create a AsyncPostBackTrigger for "btnShow"
    4.Found mistake in your code
     <asp:Button ID="btnShow" CssClass="btn btn-info" runat="server" Text="Show" OnClick="btnShow_Click" />
    5.In button click, call panel as visible true.

    For your reference, check the following code snippet :

    <asp:ScriptManager ID="ScriptManager2" EnablePageMethods="true" runat="server"></asp:ScriptManager>
    <asp:UpdatePanel ID="udpTest" runat="server" Visible="true" UpdateMode="Conditional" >
    <ContentTemplate>
    <asp:Panel ID="pnlTest" runat="server" Visible="false">
             Test <asp:Button ID="Button1" runat="server" Text="Button" /><asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
    </asp:Panel>
    </ContentTemplate> 
    <Triggers>
            <asp:AsyncPostBackTrigger ControlID=" btnShow " />
        </Triggers>
    </asp:UpdatePanel>
    <asp:Button ID="btnShow" CssClass="btn btn-info" runat="server" Text="Show" OnClick="btnShow_Click" />
    
    
    protected void btnShow_Click(object sender, EventArgs e)
    {
         pnlTest.Visible = true;
    }

    Hopefully this will be helpful for you,
    --
    with regards,
    Edwin

    Monday, December 22, 2014 10:37 PM
  • User-316651844 posted

    Thanks your answer, but it is still does not work.

    Tuesday, December 23, 2014 12:38 AM
  • User-316651844 posted

    I try with code : 

    <Triggers>
    <asp:PostBackTrigger ControlID="btnShow" />
    </Triggers>

    and web.config

    <appSettings>
    <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
    </appSettings>

    and Successful!.

    Thanks for your idea!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 23, 2014 1:08 AM