Is it possible to pass a parameter in a script when the 'OnClick' event occurs on my ASP page?

I am trying to pass a parameter in my script sub, I attempted this on an asp page :

<asp:LinkButton ID="LinSoftWares" OnClick="ProductChange(product)"  runat="server" >Softwares</asp:LinkButton>

and this for the script :

    <script runat="server">
        Sub ProductChange(ByVal StrCommand As String)
            If StrCommand = "product" Then
                If Session("BlnProductShow") = 1 Then
                    Session("BlnProductShow") = 0
                Else
                    Session("BlnProductShow") = 1
                End If
                DoRefresh()
            End If

        End Sub

        Sub DoRefresh()
            If Session("BlnProductShow") = 1 Then
                DivProduct.Style.Value = "visibility: visible"
            Else
                DivProduct.Style.Value = "visibility: hidden"
            End If

        </Sub>

    </script>

However, I encountered this error :

'product' is not declared. It may be inaccessible due to its protection level

Answer №1

My expertise lies more in C# rather than VB.Net. In C#, I would typically add a CommandArgument property with a default value and then retrieve the value on click.

Aspx:

<asp:LinkButton ID="LinSoftWares" 
                runat="server" 
                CommandArgument="Product" 
                OnClick="LinSoftWares_Click" > 
Softwares
</asp:LinkButton>

C#

protected void LinSoftWares_Click(object sender, EventArgs e)
{
    LinkButton lnkSender= (LinkButton)(sender);
    string value = lnkSender.CommandArgument;
    // Implement desired functionality here
}  

Edit:

If your argument "product" is dynamic, you can use Eval("Product") when working with data binding controls.

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

Delving into the prolonged compilation time and deciphering the root cause of the latency issue within AngularJs

Lately, I've become fixated on a particular issue that I need your help solving. My task at work involves creating a list of posts with comments, each post having the states of view, edit, and delete. To manage the posts and comments, I've devel ...

Tips for updating the color of carousel image slider indicators (arrows) specifically for the second slide

Is there a way to customize the carousel image slider indicator arrows for only the second image slide? For the first slide, I want the indicators to be black, but for the second slide, I would like them to be white. Can this be achieved? I attempted to ...

Ways to ensure a button is ready to be clicked

For my beginner chrome extension project, I am facing a specific situation that I need help with. Imagine a scenario where I have a website with a search button. When the button is clicked, two possibilities can arise: A search result appears with a butt ...

Creating a time-limited personal link with Django Rest Framework and React

I have a frontend application built with React Framework that I want to provide access to via a time-limited personal link, without the need for additional authentication functions. With approximately 1-2 new users per day, my proposed implementation is as ...

difficulty encountered when attempting to input multiple values into a single text field

There are four boxes containing values. When clicking on a box, the value should appear in a text field separated by commas if multiple boxes are selected. <li><a href="javascript:void(0)" onclick="check_stalls('A-14')" id="A-14">A-1 ...

Struggling to pinpoint the precise data value in Angular development

After sending a get request to the server, I receive data that looks like this: getStreakConfigurations(){ this.loyaltyPointsService.getStreakConfigurations().subscribe( data => { this.streakConfiguration = data console.log(this.streakConfig ...

What causes a 404 error when a GET response is returned in a Node.js server?

Having some issues with my server setup. I have a server.js file running on node js. When I try to access the CSS and JS files linked in my index.html, I keep getting 404 errors even though the files are present in the specified path. I suspect there might ...

The ng-repeat directive adds an additional line after each iteration of the list item

Whenever the angular directive ng-repeat is utilized with an <li> element, I notice an additional line appearing after each <li>. To demonstrate this issue, see the simple example below along with corresponding images. Here is a basic example ...

Having trouble importing NPM packages (e.g. Faker) in TypeScript?

Currently I am encountering an issue while attempting to import Faker into my project. The file structure is as follows: import * as faker from 'faker'; interface Test { FirstName: String, LastName: String } function create() { le ...

Saving iFrame as Image using Codemirror and html2canvas

Here are a few experiments I conducted with html2canvas: Fiddle 1 (Using html2canvas): Fiddle 2 (Using html2canvas without Codemirror): Fiddle 3 (Using html2canvas with Codemirror): Fiddle 4 (Using html2canvas with Codemirror): I recently wante ...

span element causing border-spacing problem

Is there a way to adjust the spacing between these borders? I've tried using border-spacing but it doesn't seem to be working. https://i.sstatic.net/ZY05g.png {{#each spacing}} <span class='space'> {{business}} ({{Count}}) < ...

While working on developing an asp.net core API, I encountered an error when trying to add a connection string outside of the auto-generated dbcontext

When setting up my connection string, I encountered an issue. I created the connection string with the command: Scaffold-DbContext -UseDatabaseNames = BookStoresDB Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models - force However, when trying to ...

Have you opened the DIV in a separate tab yet?

Hey there! So, I've got a question for you. I've got 4 little DIV's with text inside them. At the bottom of each DIV, there's a link that says "show more". When I click on that link, I want the respective DIV to open in a new tab. Ho ...

Incorporate an additional retrieve functionality in your asp.net web api

I'm brand new to the world of asp.net web api. I have a solid understanding of get(), put(), post() and delete(). For my application, I need to implement two additional get() methods. Here is an overview- public class StudentController : ApiControll ...

Clicking on the div will automatically refresh the page

Within a div on my website, I have placed my site logo and other elements. I am looking to set it up so that when a user clicks on the site logo (the div), they will be redirected to the homepage. What is the best way to achieve this? Should I use onclic ...

Changing $scope does not automatically refresh the selected option when using ng-options with <select> in AngularJS

My select element is structured like this: <select ng-model="exportParam" ng-options="item as item.lib for item in allExportParams | orderBy:'lib'" class="form-control"> </select> To save its state for later display, I sto ...

Error message: "Typescript is indicating that the exported external package typings do not qualify as a module"

After attempting to create my initial Typescript definition file, I've encountered a issue with the subject code found in filename.js (index.js): module.exports = { extension: extension, basename: basename, removeSuffix: removeSuffix, removeS ...

Struggling to Make This PHP Ajax Autocomplete Example Work

I watched a tutorial on YouTube that demonstrated exactly what I am attempting here. However, I am having trouble getting it to function properly. I am using the following resources: I have placed all the necessary files directly under the project folders ...

adjustBounds and expand - appearing in an entirely new location

var classBounds = new google.maps.LatLngBounds(); var query = ""; query = "SELECT 'ROAD_NUMBER', 'geometry' FROM [TABLE_REFERENCE_ID] WHERE 'ROAD_NUMBER' CONTAINS IGNORING CASE '" + searchString + "' AND 'LINK_ ...

What is the most efficient way to combine a parameter string within a JavaScript function and append it to an HTML string?

Welcome to my HTML code snippet! <div id="content"></div> Afterwards, I add an input to #content: $( document ).ready(function() { // Handler for .ready() called. var parameter = "<p>Hello</p>"; $("#content").appe ...