RadNavigation unable to hold data after postback

1 Answer 34 Views
Navigation
Jason
Top achievements
Rank 1
Jason asked on 18 Oct 2024, 06:37 PM
This is a test project I'm working on, here is the .master page

<%@ Master Language="VB" CodeFile="TelMenu.master.vb" Inherits="ZForges_TelMenu" %>

<!DOCTYPE html>

<html>
<head runat="server">
    <title></title>

    <meta name="viewport" content="width=device-width, initial-scale=1 shrink-to-fit=no">

    
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script type="text/javascript"> 

       
            function OnClientItemClicking(sender, args)
            {                
                if (args.get_item().get_navigateUrl() === null)
                {
                    args.get_item().open();
                    args.set_cancel(true);
                }
            }
          
        </script>
    </telerik:RadCodeBlock>

</head>
<body >
    <form id="form1" runat="server">       
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager>
        <div class="container-fluid">
            <div class="row BannerRow">
                <div class="col-10 col-sm-6 text-left h3">
                    Title here
                </div>                
            </div>
     
            <div class="row">
                <div class="col-12">
                    <%--<telerik:RadMenu ID="rdMenu" runat="server" ShowToggleHandle="true" OnClientItemClicking="OnClientItemClicking" ExpandAnimation-Type="None" CollapseAnimation-Type="None"></telerik:RadMenu>--%>
                    <telerik:RadNavigation ID="rdNav" runat="server" MenuButtonPosition="Left"></telerik:RadNavigation>
                </div>
            </div>

            <div class="row">
                <div class="col-12">
                    <asp:ContentPlaceHolder id="cpMain" runat="server">
                    </asp:ContentPlaceHolder>
                </div>
            </div>
        </div>

     
    </form>   
</body>
</html>

the code behind of the .master page below

Imports System.Data
Imports Telerik.Web.Device.Detection
Imports Telerik.Web.UI

Partial Class ZForges_TelMenu
    Inherits System.Web.UI.MasterPage

    Private Sub ZForges_TelMenu_Load(sender As Object, e As EventArgs) Handles Me.Load
        Try

            If Not IsPostBack Then

                LoadMenu(Session("UserID"))

             
            End If

        Catch ex As Exception
           
        End Try
    End Sub

    Private Sub LoadMenu(iUserID As Integer)
        Try
            Dim objUser As New TestClass

            'rdMenu.DataSource = objUser.GetUserMenu(iUserID)
            'rdMenu.DataTextField = "MenuName"
            'rdMenu.DataNavigateUrlField = "URL"
            'rdMenu.DataFieldID = "MenuID"
            'rdMenu.DataValueField = "MenuID"   
            'rdMenu.DataFieldParentID = "ParentID"
            'rdMenu.DataBind()


            rdNav.DataSource = objUser.GetUserMenu(iUserID)
            rdNav.DataTextField = "MenuName"
            rdNav.DataNavigateUrlField = "URL"
            rdNav.DataFieldID = "MenuID"
            rdNav.DataFieldParentID = "ParentID"
            rdNav.DataBind()

            objUser = Nothing

        Catch ex As Exception
         
        End Try
    End Sub



End Class


a simple .aspx page with a radbutton on it

<%@ Page Title="" Language="VB" MasterPageFile="~/ZForges/TelMenu.master" AutoEventWireup="false" CodeFile="Welcome.aspx.vb" Inherits="ZForges_Welcome" %>

<asp:Content ID="Content1" ContentPlaceHolderID="cpMain" Runat="Server">      
    Welcome Page    
    <telerik:RadButton ID="btnSearch" runat="server" Text="RadButton"></telerik:RadButton>

</asp:Content>


the radnavigation loads just fine for the first time, then its contents disappear after a postback
when I click the radbutton on the child page (welcome.aspx) the rad navigation contents disappear, if I use a radmenu instead, its able to hold the values

can someone explain whats going on?

1 Answer, 1 is accepted

Sort by
0
Attila Antal
Telerik team
answered on 22 Oct 2024, 08:55 AM

Hi Jason,

Unlike other server components, the RadNavigation requires the data on every cycle of the page. The solution is to move the Binding logic out of the "If Not IsPostBack Then" condition, so it can get the data every time.

 Private Sub ZForges_TelMenu_Load(sender As Object, e As EventArgs) Handles Me.Load
        Try
            'If Not IsPostBack Then
               LoadMenu(Session("UserID"))
            'End If
        Catch ex As Exception
           
        End Try
    End Sub

Note: When troubleshooting, keep in mind the "Try/Catch" blocks as they will hide any exception, thus not revealing what is wrong. While developing, I highly recommend that you comment them out. Only use this when trying to hide real exceptions from the end user.

Regards,
Attila Antal
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources
Tags
Navigation
Asked by
Jason
Top achievements
Rank 1
Answers by
Attila Antal
Telerik team
Share this question
or