Unable to trigger LinkButton click event in asp.net

I am having trouble with the link button onclick event not firing. I have tried rewriting the code and redirecting directly on button click function, but it never reaches the redirectUser() line. Can someone assist me in solving this issue?

HTML:

<li><asp:LinkButton ID="dashbut" runat="server" 
           CausesValidation="false" 
           OnClick="dashbut_Click"
           Text="Dashboard">
               <img src="images/dash.png" height="25" width="25" class="fa fa-tachometer" /><span> Dashboard</span>
    </asp:LinkButton>
 </li>

Code Behind:

protected void dashbut_Click(object sender, EventArgs e)
{
    //Response.Redirect("~/Views/Portal/AdminDashboard.aspx");
    redirectUser();
}

private void redirectUser()
{
    string myConnection = dbController.connectionString;
    SqlConnection conn = new SqlConnection(myConnection);

    string userCheckQuery = "SELECT UserType from tblUsers where ID = '" + USERid + "'";
    SqlCommand cmd1 = new SqlCommand(userCheckQuery, conn);
    conn.Open();
    bool userType = (bool)cmd1.ExecuteScalar();
    conn.Close();

    if (userType == true)
    {
        Response.Redirect("~/Views/Portal/AdminDashboard.aspx");
    }
    else if (userType == false)
    {
        Response.Redirect("~/Views/Portal/Dashboard.aspx");
    }
}

EDIT:

It appears that the LinkButton click event is not firing due to a JS error. There is a TypeError related to theForm.submit. When checking the browser console, the error message is: Uncaught TypeError: theForm.submit is not a function

<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['form1'];
if (!theForm) {
    theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}
//]]>
</script>

The error is occurring on the theForm.submit(); line. I am unable to resolve this on my own. Any assistance is appreciated.

Answer №1

I encountered an issue with JavaScript where a button with the ID=submit was causing conflicts with the submit() function on the form, resulting in an error. I found a helpful solution on Stack Overflow. Thumbs up to the wonderful Stack Overflow community for their assistance.

Answer №2

Apologies for my inability to comment as a result of insufficient reputation points. I am curious to find out if CauseValidation needs to be set to false.

You may want to consider including usesubmitbehavior="false".

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

The context provider in Next.js wraps the App component with a layout component specific to each page, resulting in data

Within my project, I have an authentication context component wrapping the main app component. Simultaneously, I am also attempting to implement a page-specific layout component based on the Next.js documentation found here. I'm unsure if my approach ...

Migrating to Angular Universal for server-side rendering with an external API server

Thank you for taking the time to read my query. I have developed a project using server-side Node.js and client-side Angular 6. The purpose of the app is to provide information on cryptocurrency prices and details. I am now looking to transition my Angu ...

Is it feasible to relocate an embedded swf file from one tag to another?

My HTML contains two containers for embedded swf files: <div id="player1"></div> <div id="player2"></div> If I load an embedded video into the first div (player1) like this: swfobject.embedSWF("someURL","player1"); Is it possibl ...

I'm curious about something as a beginner. Can you explain what **.config.js and **.vue.js files are? How do they differ from regular .js files

I have a simple question that I haven't been able to find the answer to through searching. I've come across files like vue.config.js generated by vue-cli, as well as files like Content.vue.js. At first, I assumed that after the period was the fi ...

ng-binding does not sync with input field

Check out this JavaScript snippet angular.module('myApp') .controller('HeaderCtrl', function($scope) { $scope.searchBooking = "test"; $scope.goToBooking = function() { console.log($scope.searchBooking); ...

Utilizing the $scope variable within an event in the Google Maps API

I am having an issue using $scope within this function. Where should I define the argument $scope so that it works properly? Thank you Below is the basic structure of my code with key lines included: myApp.controller('myCtrl', ['$scope&ap ...

There was an issue with the Discord.js (v12) Giveaway Command that resulted in an error stating "Error: Cannot read property 'hasPermission' of undefined"

Hey everyone, I'm trying to develop my own Discord bot and I want to add a giveaway command to it. I found an example code online that I tried to implement, but unfortunately, it's not working as expected... const ms = require('ms'); c ...

Applying a class to a specific element within another element using jQuery

This section pertains to a user account. When the user clicks on the edit button, I would like an edit box to appear within the same element as the button. Here is the HTML markup: <div class="col account"> <strong>Account Settings</st ...

What is the process of transferring JavaScript code to an HTML file using webpack?

I am looking to display an HTML file with embedded CSS, fonts, and JS (not linked but the content is inside). I have the CSS and fonts sorted out, but I am struggling to find a solution for the JavaScript. My project is based on Node.js. ...

Messy code appeared when sending an AJAX post to JBoss EAP 7 without using encodeURIComponent

Initially, the project functions smoothly on tomcat using UTF-8 and jboss eap 6 with UTF-8 page encoding as well. Additionally, the jboss configuration includes: <servlet-container name="default" default-buffer-cache="default" stack-trace-on-error="loc ...

Saving the previous component's DOM in a React application

Understanding the Root.js File const Root = () => ( <HashRouter> <div> <Route exact path="/" component={Main}/> <Route path="/main/:page" component={Main}/> <Route path="/detail ...

How to make a form in PHP that can be saved?

I have put together a straightforward, yet lengthy HTML form and I am in need of a way for users to save their progress on the form and return to it at a later time (security is not a major concern). However, I am struggling with how to save the form' ...

Encountering a 500 error in Angular while utilizing forkJoin for calling API services

In my Angular 7 project, I have implemented a call in the ngOnInit method to two different API routes to fetch some data using forkJoin. Here is how I have set it up: ngOnInit() { debugger this.route.params.pipe( switchMap(params => for ...

What is the best method for retrieving the complete error message from my client-side Node and Express server?

When I send a request to my express route and it returns a 400 status along with an error message, I am facing an issue on the client-side. The alert message only displays "Object object" instead of the actual error message that I see on the server side. U ...

Unable to utilize a function within a mongoose schema

I encountered an issue while attempting to access the schema methods of a mongoose schema in TypeScript. Schema const userSchema: Schema<IUser> = new Schema( { name: { type: String, required: [true, "Name is required"], ...

Save a JSON object from a URL into a JavaScript variable using jQuery

I am trying to figure out how to use the .getJSON() function to store a JSON object as a JavaScript variable. Can someone guide me through this process? var js = $.getJSON(url, function(data) {...} ); Is it necessary to include the function(data) { ...

Generate a CSV file using Javascript

I am working with an HTML table (table id='testTable') and a button in the HTML code: <button id="btnExport" onclick="javascript:xport.toCSV('testTable');">CSV</button> There is also JavaScript code involved: toCSV: func ...

How to efficiently store and manage a many-to-many relationship in PostgreSQL with TypeORM

I have a products entity defined as follows: @Entity('products') export class productsEntity extends BaseEntity{ @PrimaryGeneratedColumn() id: number; //..columns @ManyToMany( type => Categories, categoryEntity => cat ...

Transform JSON query conditions into MongoDB/Mongoose commands

I'm currently developing an application using Angular 8 on the front end and NodeJS 12 with MongoDB 4 / Mongoose 5 on the back end. Using the Angular query builder module, I have generated a query in JSON format. This JSON object will be sent to the ...

Vue component encounters issue with exporting JavaScript functions

I decided to streamline my code by moving some functions into a JavaScript file like this: [...] function changeToEditView(reportId) { let pathEdit="/edit/"+reportId; this.$router.push({ path: pathEdit, replace: true }); } [...] export {c ...