Guidelines for Redirecting a Page with an Onclick Function Triggered by Clicking a Menu in ASP Using JavaScript

My VB Code Starts Here

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 Structure

<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>

To redirect to another page when the menu is clicked, I have JavaScript like this:

<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>

If you click on "Home", it should redirect you to another page. How can this be achieved? I've been trying for the past few days but haven't found a solution that meets my requirements. Can someone help me out? Thank you in advance!

Answer №1

give this a shot

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

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I'm currently working with React and experiencing issues with my components being unrendered

I'm currently navigating a React tutorial and I'm having issues getting this code to display some buttons. I'm utilizing codepen.io to work on the code and can provide the tutorial link if needed. const clips = [ { keyCode: 81, key ...

Get a specific attribute of an object instead of directly accessing it

Is there a way to retrieve a specific object property in my checkForUrgentEvents method without referencing it directly? I attempted using Object.hasOwnProperty but it didn't work due to the deep nesting of the object. private checkForUrgentEvents(ur ...

Tips for choosing the default tab on Bootstrap

I have a question about an issue I am facing with my Angular Bootstrap UI implementation. Here is the code snippet: <div class="container" ng-controller='sCtrl'> <tabset id='tabs'> <tab heading="Title1"> ...

Error: 'require' is undefined in react.production.min.js during production deployment

Greetings! I am encountering some difficulties while trying to build on production: the error "require is not defined" is being caused by react.production.min.js. Below are my webpack.config.js and package.json files: webpack.config.js const path = requi ...

React's JS is having trouble accepting cookies from the express server

I've encountered an issue where sending cookies from my express server using res.cookie() is not working with the front end. Even though I include {withCredentials:true} in the get requests, the cookies are not being set in the browser's applicat ...

Capture and set the new value of the Datetime picker in MUI upon user's acceptance click

import React from 'react' import { Stack, Typography } from '@mui/material' import { DateTimePicker } from '@mui/x-date-pickers/DateTimePicker' import { renderTimeViewClock } from '@mui/x-date-pickers/timeViewRenderers&ap ...

Searching for a way to display just a portion of a rendered HTML page using JavaScript

With the JavaScript code window.print(), it is possible to print the current HTML page. If there is a div in an HTML page (such as a page generated from an ASP.NET MVC view), the aim may be to only print that specific div. Is there any jQuery unobtrusive ...

Function is raising an error with the wrong value or text

I am currently testing a form that I am in the process of developing. My goal is to have different values returned each time I click on a different item from the dropdown menu. If this explanation isn't clear, please take a quick look at my pen for cl ...

Why is it possible for the EXPRESS+EJS template to access CONFIG without explicitly passing it when rendering?

Currently exploring my knowledge of node.js alongside express and the ejs template. As I delved into some code, I stumbled upon the fact that they were able to invoke config in the template without explicitly passing it as a variable during rendering. You ...

ng-disabled directive not functioning as expected

Trying to develop a customized button directive, I aim to utilize the ng-disabled attribute and link it to a variable within the scope. Check out the HTML snippet below: <div ng-controller="MyCtrl"> <btn dis="disableBtn"></btn> </d ...

Determine the dropdown list value by analyzing the final two variables in a textfield

In my textfield, car registration numbers are meant to be entered. These registrations are based on years in the format GT 74454 12, with the last two digits "12" representing the year 2012. I am looking for a script that can automatically detect the last ...

Troubleshooting: Difficulty with jQuery script to change images

I am trying to modify the src attribute of an img tag using the code below, but it doesn't seem to be working. Can anyone help me figure out what's wrong? <img id='logo_image'/> <span onclick='$(logo_image).attr("src", "i ...

The console is showing the Ajax Get request being logged, but for some reason it is not displaying on the

Could someone please explain why this response isn't displaying on the page? $.ajaxPrefilter( function (options) { if (options.crossDomain && jQuery.support.cors) { var http = (window.location.protocol === 'http:' ? &apos ...

Steps for displaying the output of a post request in printing

I am currently working on creating a basic search bar functionality for daycares based on user input. I am utilizing a post request to an API and receiving back a list of daycares that match the input. Below is the code snippet: <template> <div ...

Cannot attach Identity to services within the HostBuilder

Upon starting a new project that utilizes ASP.NET Core 7, I encountered an issue while attempting to create a custom authorizationHandler for Role management. Although my custom handler fires successfully, the user context lacks any information such as cla ...

Want to achieve success with your AJAX calls in JavaScript? Consider using $.get

As I clean up my JavaScript code, I am looking to switch from using $.ajax to $.get with a success function. function getresults(){ var reqid = getUrlVars()["id"]; console.log(reqid); $.ajax({ type: "POST", url: "/api/ser/id/", ...

What is the best way to add a style to the currently active link on a NavLink component using the mui styled() function

I have a custom NavLink component that I want to style with an ".active" class when it is active. However, I am not sure how to achieve this using the "styled()" function in MUI. Does anyone know how to accomplish this? Below is the code for my custom Nav ...

A guide to performing individual file testing in Quasar testing

I need to run specific test code in my Quasar project without running all tests. I've tried using the following commands, but they still run all test files. quasar test --unit jest -t "demo/demo.spec.js" quasar test --unit jest --spec "demo/demo.spec ...

Using TinyMCE editor to handle postbacks on an ASP.NET page

I came up with this code snippet to integrate TinyMCE (a JavaScript "richtext" editor) into an ASP page. The ASP page features a textbox named "art_content", which generates a ClientID like "ctl00_hold_selectionblock_art_content". One issue I encountered ...

Encountering a "Duplicate identifier error" when transitioning TypeScript code to JavaScript

I'm currently using VSCode for working with TypeScript, and I've encountered an issue while compiling to JavaScript. The problem arises when the IDE notifies me that certain elements - like classes or variables - are duplicates. This duplication ...