Validation not working on __doPostBack call

2 posts, 0 answers
  1. Martin Gartmann
    Martin Gartmann avatar
    51 posts
    Member since:
    Apr 2004

    Posted 05 Sep 2010 Link to this post

    Hi,

    i have a control with multiple input boxes where i need to validate required values.

    Following http://www.telerik.com/help/aspnet/ajax/ajxexclude.html i have added a submit button.

    When is use in page_load

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If Not Page.IsPostBack Then
                btnStoreCustom.Attributes.Add("onclick", String.Format("realPostBack('{0}', ''); return false;", btnStoreCustom.UniqueID))
            End If
        End Sub

    my code code

    Protected Sub btnStoreCustom_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnStoreCustom.Click
            ' save all custom made values in Session Variables for future use
            Session("MP1A") = CInt(rntbPM1A.Value)
            Session("MP1B") = CInt(rntbPM1B.Value)
            Session("MP2A") = CInt(rntbPM2A.Value)
            Session("MP2B") = CInt(rntbPM2B.Value)
            Session("MP3A") = CInt(rntbPM3A.Value)
            Session("MP3B") = CInt(rntbPM3B.Value)
            Session("MP4A") = CInt(rntbPM4A.Value)
            Session("MP4B") = CInt(rntbPM4B.Value)
            Session("MP5A") = CInt(rntbPM5A.Value)
            Session("MP5B") = CInt(rntbPM5B.Value)
            Session("MP6A") = CInt(rntbPM6A.Value)
            Session("MP6B") = CInt(rntbPM6B.Value)
            Session("MP7A") = CInt(rntbPM7A.Value)
            Session("MP7B") = CInt(rntbPM7B.Value)
            Session("MP8A") = CInt(rntbPM8A.Value)
            Session("MP8B") = CInt(rntbPM8B.Value)
            Session("MP9A") = CInt(rntbPM9A.Value)
            Session("MP9B") = CInt(rntbPM9B.Value)
            Session("MP10A") = CInt(rntbPM10A.Value)
            Session("MP10B") = CInt(rntbPM10B.Value)
            Session("MP11A") = CInt(rntbPM11A.Value)
            Session("MP11B") = CInt(rntbPM11B.Value)
            Session("MP12A") = CInt(rntbPM12A.Value)
            Session("MP12B") = CInt(rntbPM12B.Value)
            Session("MP13A") = CInt(rntbPM13A.Value)
            Session("MP13B") = CInt(rntbPM13B.Value)
            Session("MP14A") = CInt(rntbPM14A.Value)
            Session("MP14B") = CInt(rntbPM14B.Value)
            Session("MP15A") = CInt(rntbPM15A.Value)
            Session("MP15B") = CInt(rntbPM15B.Value)
            Session("MP16A") = CInt(rntbPM16A.Value)
            Session("MP16B") = CInt(rntbPM16B.Value)
            Session("MP17A") = CInt(rntbPM17A.Value)
            Session("MP17B") = CInt(rntbPM17B.Value)
            Session("Weight") = CInt(rntbGewicht.Value)
            Session("Height") = CInt(rntbGroesse.Value)
        End Sub

    is executed but no validating was done. 

    In case of excluding the  btnStoreCustom.Attributes.Add

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
           If Not Page.IsPostBack Then
               '  btnStoreCustom.Attributes.Add("onclick", String.Format("realPostBack('{0}', ''); return false;", btnStoreCustom.UniqueID))
           End If
       End Sub

    validation is done, but the code is not executed.

    My ASPX for the button looks like this

    <asp:Button ID="btnStoreCustom" runat="server" 
         Text="Diese Daten zwischenspeichern!" PostBackUrl="~/overlay.aspx" 
         ValidationGroup="AllPoint" CommandName="Submit" CausesValidation="True" />

    Any suggestion on this task ?

    Kind regards

    Martin Gartmann
  2. Cori
    Cori avatar
    562 posts
    Member since:
    Jul 2010

    Posted 07 Sep 2010 Link to this post

    Hello Martin,

    I would suggest using the EnableAJAX approach, listed in that help document, to disable the Ajax postback. The reason being, you need to add the validation group that it uses to use the real postback approach.

    I hope that helps.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top