RadMenu client side validation

4 posts, 0 answers
  1. Shamil
    Shamil avatar
    2 posts
    Member since:
    Jan 2014

    Posted 20 Jan 2014 Link to this post

    This is an existing VS2002 project using ComponentArt menu for page navigation. Currently menu items are attached to the client side event for page

    validation. Upon the page submit, the control is directed to client side script for page validation. On successful page validation, the control is passed

    onto server side script for saving the data.

    This control is not supported in VS2012 enviornment, so we are in process of upgrading the control with RadMenu control.

    Currently the ComponentArt menu control is placed inside Header page(user control) and this page is inherited in all other pages using base page concept

    to render the menu.

     We are having issue using RadMenu control in the same fashion.

     The issue is when we associated custom client side script to RadMenu item, the control is going to custom Client side script as intended for the validation,

    but after the validation it is going back to RadMenu built-in client side event (OnClientItemClicked) again for client side click rather than passing the

    clontrol to RadMenu Server side click event OnItemClick="RadMenu1_ItemClick.

    Issue is, if the custom client side validation fails, we want to stop there itself rather going back to built-in client side for further validation.

     
    Is it possible to stop the control going to radMenu built-in validation, if the custom client side validation fails ?

  2. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 23 Jan 2014 Link to this post

    Hello,

    I am glad to hear that you decided to use our RadMenu control in your application.

    As far as I understand you are trying to stop firing the the RadMenu client-side event ClientItemClicked and the server-side event ItemClick. An easy and convenient way of achieving such scenario would be to use the RadMenu ClientItemClicking event handler for implementing your custom client validation. If it fails you can simply cancel any further execution so the client-side click and server-side click events will not be fired. I have attached a sample web site project that contains the RadMenu in user control and a page that includes this user control. The console log messages shows in what sequence the events are processed. In order to review the log you can open the console tab of your browser's developer tools.

    If this is not exact functionality you want to achieve, please explain which events you want to prevent if your custom client-side validation fails. A sample scenario that illustrates your case will be very helpful.

    Please refer to our RadMenu client-side programming section and specifically to our RadMenu client-side events help article for more information.


    Regards,
    Boyan Dimitrov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Shamil
    Shamil avatar
    2 posts
    Member since:
    Jan 2014

    Posted 23 Jan 2014 Link to this post

    Thanks for your reply.

    Assume I have Page1.aspx,Page2.aspx,Page3.aspx,
    I created a a user control ie. Header Page (System.Web.UI.UserControl) , where I put a radMenu.
    I added this user control (Header Page) in Page1,Page2 and Page3.
    In the page Load of the UserControl ,I am adding MenuItems as follows.
    Note :clsNavigationState object value will be assigned from Page1,Page2,Page3 etc..

    Take the example of btnClear, I am attching a JavaScript function On_Clear() using objMenuButton.AttributesValue.
    objMenuItem.Attributes.Add("onclick", "return " + objMenuButton.AttributesValue + "")

    Assume Page1 has 10 TextBoxes , Page2 has 5 Dropdowns and Page3 has 12 TextBoxes .

    ***Scenario 1 - I have Submit and Clear Buttons***
    When I click ClearButton On Page1 , it should clear 10 TextBoxes in Page1 and stop the execution there.
    ***Scenario 2 - I have Submit and Clear Buttons***
    When I Click Submit Button On Page1 , it should validate 10 TextBoxes in Page1 .if validation fails stop the execution there
    else continue and PostBack the Page

    QUESTION IS How do I notify the ClientItemClicking event to Proceed or Not from the above Scenario.

    //Page1
    function On_Clear()
    {
    txt1.value = "";
    txt2.value = "";
    .
    .
    .
    txt10.value = "";
     
    return false;
     
    }
    //Page2
    function On_Clear()
    {
    drp1.Clear();
    drp2.Clear();
    .
    .
    .
    drp3.Clear();
    return false;
    }


    Private Function addMenuItemRad(ByVal objMenuButton As clsMenuButton) As Web.UI.RadMenuItem
            Try
                Dim objMenuItem As New Web.UI.RadMenuItem
                objMenuItem.Value = Replace(objMenuButton.text, " ", "")
                objMenuItem.Text = objMenuButton.text
                objMenuItem.Enabled = objMenuButton.enabled
                objMenuItem.Visible = objMenuButton.visible
                objMenuItem.Attributes.Add("onclick", "return " + objMenuButton.AttributesValue + ""'09/29/05
                Return objMenuItem
            Catch ex As Exception
                m_oErrHandler.SendHtmlErrorEmail(ex, False)
                Throw ex
            End Try
     End Function
     
     
      Public Sub ShowTransactionButtons(ByVal objNavigationState As clsNavigationState)
            Try
     
                mnuTransactionRad.Items.Clear()
     
                If objNavigationState.btnNew.visible Then
                    mnuTransactionRad.Items.Add(addMenuItemRad(objNavigationState.btnNew))
                End If
     
                If objNavigationState.btnInsert.visible Then
                    mnuTransactionRad.Items.Add(addMenuItemRad(objNavigationState.btnInsert))
                End If
     
                If objNavigationState.btnUpdate.visible Then
                    mnuTransactionRad.Items.Add(addMenuItemRad(objNavigationState.btnUpdate))
                End If
     
                If objNavigationState.btnCopy.visible Then
                    mnuTransactionRad.Items.Add(addMenuItemRad(objNavigationState.btnCopy))
                End If
     
                If objNavigationState.btnDelete.visible Then
                    mnuTransactionRad.Items.Add(addMenuItemRad(objNavigationState.btnDelete))
                End If
     
                If objNavigationState.btnPrint.visible Then
                    mnuTransactionRad.Items.Add(addMenuItemRad(objNavigationState.btnPrint))
                End If
     
                If objNavigationState.btnProcess.visible Then
                    mnuTransactionRad.Items.Add(addMenuItemRad(objNavigationState.btnProcess))
                End If
     
                If objNavigationState.btnRefresh.visible Then
                    mnuTransactionRad.Items.Add(addMenuItemRad(objNavigationState.btnRefresh))
                End If
     
                If objNavigationState.btnSubmit.visible Then
                    mnuTransactionRad.Items.Add(addMenuItemRad(objNavigationState.btnSubmit))
                End If
     
                If objNavigationState.btnClear.visible Then
                    mnuTransactionRad.Items.Add(addMenuItemRad(objNavigationState.btnClear))
                End If
     
                If objNavigationState.btnCancel.visible Then
                    mnuTransactionRad.Items.Add(addMenuItemRad(objNavigationState.btnCancel))
                End If
                 
     
                mnuTransaction.ApplyLooks()
            Catch ex As Exception
                m_oErrHandler.SendHtmlErrorEmail(ex, False)
                Throw ex
            End Try
        End Sub
     
     
     
    Public Class clsMenuButton
     
        '''''''''''''''''''''''''''''''''''''''''
        '*** Transaction Buttons ****(STARTS)****
        '''''''''''''''''''''''''''''''''''''''''
        Private m_Text As String
        Private m_Enabled As Boolean
        Private m_Visible As Boolean
        Private m_AttributesValue As String
     
        Public Property text() As String
            Get
                Return m_Text
            End Get
            Set(ByVal Value As String)
                m_Text = Value
            End Set
        End Property
     
        Public Property enabled() As Boolean
            Get
                Return m_Enabled
            End Get
            Set(ByVal Value As Boolean)
                m_Enabled = Value
            End Set
        End Property
     
        Public Property visible() As Boolean
            Get
                Return m_Visible
            End Get
            Set(ByVal Value As Boolean)
                m_Visible = Value
            End Set
        End Property
     
        Public Property AttributesValue() As String
            Get
                Return m_AttributesValue
            End Get
            Set(ByVal Value As String)
                m_AttributesValue = Value
            End Set
        End Property
        '''''''''''''''''''''''''''''''''''''''''
        '*** Transaction Buttons ****(ENDS)******
        '''''''''''''''''''''''''''''''''''''''''
    End Class
     
     
     
    Public Class clsNavigationState
     
     
        '''''''''''''''''''''''''''''''''''''''''
        '*** Transaction Buttons ****************
        '''''''''''''''''''''''''''''''''''''''''
        Private m_strTransactionState As String
        Private m_btnNew As New clsMenuButton
        Private m_btnInsert As New clsMenuButton
        Private m_btnUpdate As New clsMenuButton
        Private m_btnCopy As New clsMenuButton
        Private m_btnDelete As New clsMenuButton
        Private m_btnCancel As New clsMenuButton
        Private m_btnClear As New clsMenuButton
        Private m_btnRefresh As New clsMenuButton
        Private m_btnPrint As New clsMenuButton
        Private m_btnProcess As New clsMenuButton
        Private m_btnSubmit As New clsMenuButton
        Private m_strUserName As String
     
     
     
     
     
        Public Sub setDefaultTransactionButtons()
            btnNew.text = "New"
            btnInsert.text = "Insert"
            btnUpdate.text = "Update"
            btnCopy.text = "Copy"
            btnDelete.text = "Delete"
            btnCancel.text = "Cancel"
            btnClear.text = "Clear"
            btnRefresh.text = "Refresh"
            btnPrint.text = "Print"
            btnProcess.text = "Process"
            btnSubmit.text = "Submit"
            btnCreateWMSJob.text = "Create WMS Job"
     
            btnNew.enabled = False
            btnInsert.enabled = False
            btnUpdate.enabled = False
            btnCopy.enabled = False
            btnDelete.enabled = False
            btnCancel.enabled = False
            btnClear.enabled = False
            btnRefresh.enabled = False
            btnPrint.enabled = False
            btnProcess.enabled = False
            btnSubmit.enabled = False
            btnCreateWMSJob.enabled = False
     
            btnNew.visible = False
            btnInsert.visible = False
            btnUpdate.visible = False
            btnCopy.visible = False
            btnDelete.visible = False
            btnCancel.visible = False
            btnClear.visible = False
            btnRefresh.visible = False
            btnPrint.visible = False
            btnProcess.visible = False
            btnSubmit.visible = False
            btnCreateWMSJob.visible = False
     
        End Sub
     
        Public Property btnNew() As clsMenuButton
            Get
                Return m_btnNew
            End Get
            Set(ByVal Value As clsMenuButton)
                m_btnNew = Value
            End Set
        End Property
     
        Public Property btnInsert() As clsMenuButton
            Get
                Return m_btnInsert
            End Get
            Set(ByVal Value As clsMenuButton)
                m_btnInsert = Value
            End Set
        End Property
     
        Public Property btnUpdate() As clsMenuButton
            Get
                Return m_btnUpdate
            End Get
            Set(ByVal Value As clsMenuButton)
                m_btnUpdate = Value
            End Set
        End Property
     
        Public Property btnCopy() As clsMenuButton
            Get
                Return m_btnCopy
            End Get
            Set(ByVal Value As clsMenuButton)
                m_btnCopy = Value
            End Set
        End Property
     
        Public Property btnDelete() As clsMenuButton
            Get
                Return m_btnDelete
            End Get
            Set(ByVal Value As clsMenuButton)
                m_btnDelete = Value
            End Set
        End Property
     
        Public Property btnCancel() As clsMenuButton
            Get
                Return m_btnCancel
            End Get
            Set(ByVal Value As clsMenuButton)
                m_btnCancel = Value
            End Set
        End Property
     
        Public Property btnClear() As clsMenuButton
            Get
                Return m_btnClear
            End Get
            Set(ByVal Value As clsMenuButton)
                m_btnClear = Value
            End Set
        End Property
     
        Public Property btnRefresh() As clsMenuButton
            Get
                Return m_btnRefresh
            End Get
            Set(ByVal Value As clsMenuButton)
                m_btnRefresh = Value
            End Set
        End Property
     
        '''''''''''''''''''''''''''''''''''''''''
        '*** Transaction Buttons ****(ENDS)******
        '''''''''''''''''''''''''''''''''''''''''
     
    End Class
  5. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 28 Jan 2014 Link to this post

    Hello,

    Please find attached a sample project that contains a user control "HeaderUserControlVB" and two aspx pages. In both pages the user control is included. The main difference comes in the code behind:
    • In the page load event handler you can find the RadMenu control using the user control as shown in the attached sample. Then you can create different items for the specific page using your method "addMenuItemRad". I would suggest attaching the RadMenu OnClientItemClicking client-side event handler from the code behind and create a function with the same name in the markup code. This way you can implement a custom logic to be executed when a menu item is clicked based on the current page- if this is Page1.aspx you will clear the text boxes and if this is Page2.aspx you can clear the drop down lists. In the comments you can find out how you can get the clicked menu item clicked item and perform different logic based on the fact which menu item is clicked - for example the clear or the new button.

    Hope that this will be helpful.


    Regards,
    Boyan Dimitrov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
Back to Top