How to redirect the Page While Onclick Function when Click the Menu in asp using JavaScript?

376 Views Asked by At

My vb Code Bedind Like

   Private Function GetCategories() As DataTable

        Dim strcon As String = ConfigurationManager.ConnectionStrings("KRGCbiz").ConnectionString
        Dim connection As New SqlConnection(strcon)
        Dim selectCommand As New SqlCommand("SELECT MenuId,Menus FROM MenusDetails ", connection)

        Dim dt As New DataTable()
        Try
            connection.Open()
            Dim reader As SqlDataReader = selectCommand.ExecuteReader()
            If reader.HasRows Then
                dt.Load(reader)
            End If
            reader.Close()
        Catch generatedExceptionName As SqlException
            Throw
        Finally
            connection.Close()
        End Try
        Return dt
    End Function
    Private Function GetAllCategories() As DataTable

        Dim strcon As String = ConfigurationManager.ConnectionStrings("KRGCbiz").ConnectionString
        Dim connection As New SqlConnection(strcon)
        Dim selectCommand As New SqlCommand("select SubMenuId,SubMenu,MenuId,Menus from Submenus ", connection)
        Dim dt As New DataTable()
        Try
            connection.Open()
            Dim reader As SqlDataReader = selectCommand.ExecuteReader()
            If reader.HasRows Then
                dt.Load(reader)
            End If
            reader.Close()
        Catch generatedExceptionName As SqlException
            Throw
        Finally
            connection.Close()
        End Try
        Return dt
    End Function

Protected Sub rptCategories_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptCategories.ItemDataBound
        If True Then
            If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
                If allCategories IsNot Nothing Then
                    Dim sb As New StringBuilder()
                    Dim drv As DataRowView = TryCast(e.Item.DataItem, DataRowView)
                    Dim ID As String = drv("MenuId").ToString()
                    Dim Menu As String = drv("Menus").ToString()
                    Dim rows As DataRow() = allCategories.[Select](Convert.ToString("MenuId=") & ID, "Menus")
                    If Menu = "Home" Then
                        //drv("Menus").Attributes.Add("onclick", "return Home();")
                    End If
                    If rows.Length > 0 Then

                        sb.Append("<ul>")
                        For Each item As DataRow In rows
                            sb.Append("<li><a href='#' >" + item("SubMenu") + "</a></li>")

                        Next
                        sb.Append("</ul>")
                        TryCast(e.Item.FindControl("ltrlSubMenu"), Literal).Text = sb.ToString()
                    End If
                End If
            End If
        End If

    End Sub

My Aspx Page Like

   <asp:repeater ID="rptCategories" runat="server" OnItemDataBound="rptCategories_ItemDataBound">
                    <headertemplate>
                        <div class="menu"><ul>
                    </headertemplate>
                    <itemtemplate>
                        <li>
                            <a href='#'> <%#Eval("Menus")%></a>
                            <asp:literal ID="ltrlSubMenu" runat="server"></asp:literal>
                        </li>

                    </itemtemplate>
                <footertemplate>
                       </ul></div>
                </footertemplate>
                </asp:repeater>

I want to Redirect the Page when drv("Menus")="Home",, If i click the Menu Home Means i want to Redirect the Page, How to Do? My Java script Like

    <script type="text/javascript">

        function alertMe() {
        alert("License");
        window.location.replace('SoftwareLicenseDetails.aspx');
     return false;
}

  function Home() {
        alert("Home");
        window.location.replace('SystemDetails.aspx');
        return false ; 
}
  </script>

output Like

enter image description here

if click home Means want to Redirect another Page
How to Do? I tried Last 4 days But i didn't Get Anything For My Requirement, Help Me!! Thanks in advance!!

1

There are 1 best solutions below

2
On

try this window.location.href = 'SystemDetails.aspx';