Interactive coding from an online source

I recently developed a unique web control that performs client-side validation on text input within a textbox. This custom web control includes embedded JavaScript as a resource, which triggers a confirm alert box during the validation process.

My goal is to allow users to customize the message displayed in the alert box by setting it through a property of the web control, similar to how standard ASP.NET validation controls use the ErrorMessage property.

If anyone has suggestions on the best approach to integrate this property into my existing embedded JavaScript function, I would greatly appreciate your advice.

Snippet from Embedded JavaScript Function

function checkDeduction(sender, eventArgs) {
    var dNewVal = eventArgs.get_newValue();
    if (dNewVal > 0) {
        var bRetVal = confirm("custom msg here");
        if (!bRetVal) {
           dNewVal = dNewVal * -1;
           sender.set_value(dNewVal);
        }
    }
}

Answer №1

In order to accomplish this task, I included a unique attribute in my custom control during the PreRender event:

protected override void OnPreRender(EventArgs e)
{
        this.Attributes.Add("CustomAttribute", "unique custom value from public property");
        ...
        base.OnPreRender(e);
}

Subsequently, I could retrieve the error message on the client side using the following method:

alert(sender.getAttribute('CustomAttribute'));

And that's it!

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

What is the reason for the lack of invocation of the next-auth jwt callback during page transitions?

Utilizing the next-auth Credentials provider, I have set up authentication in my Next.js application with a custom Django backend. Below is my jwt callback function: async jwt(token, user, account) { if (user && account) { // The user ha ...

Steps for transforming Object A into an array of objects, each containing the properties and assigned values and labels from Object A

I have an object with specific key-value pairs and I would like to transform it into an array where each item has a label and a value: { "id": 12432, "application": "pashmodin", "unit": null, "status": ...

Tips for designing JavaScript functionality to avoid handling transparent image regions when hovering and clicking

I have searched through various sources on this subject, but none seem to directly address my specific requirements. My main objective is to replicate the Nike ID Flash-based customization using html5, css3, and javascript. My initial thought was to cut a ...

Having trouble getting an HTML form to function with Ajax and PHP?

Seeking assistance from anyone who can lend a hand. I am delving into the complexities of Ajax, and I'm encountering issues where it seems like the script is being completely ignored or perhaps I'm just making a rookie mistake. Prior to display ...

Exploring the functionality of the onblur HTML attribute in conjunction with JavaScript's ability to trigger a

How do the HTML attribute onblur and jQuery event .trigger("blur") interact? Will both events be executed, with JavaScript this.trigger("blur") triggering first before the HTML attribute onblur, or will only one event fire? I am using ...

Handling connections with MongoDB in a serverless Express application without managing server

Currently, my setup includes serverless on AWS using Node.js and MongoDB Atlas as the database. While I am on the trial version, which allows a maximum of 500 connections, I have noticed that my code is not disconnecting the database when the process ends ...

Spin text on the center point of an html5 canvas

I am looking for a way to rotate HTML5 canvas text using dynamic X and Y values from its center position. Despite following the code provided in a stackoverflow post HTML5 rotate text around it's centre point, I am experiencing the issue of the text ro ...

A guide on verifying if two arrays of integers are permutations using JavaScript

Is there a way to determine if two sets of integers in JavaScript are permutations? For example, given the arrays: a = [1, 2, 3, 4, 5] and b = [2, 3, 5, 1, 4] I want a function that will return true if they are permutations of each other. ...

JavaScript Lint Warning: Avoid declaring functions inside a loop - unfortunately, there is no way to bypass this issue

In my React JS code snippet, I am attempting to search for a value within an object called 'categories' and then add the corresponding key-value pair into a new map named sortedCategories. var categoriesToSort = []; //categoriesToSort contains ...

How to align two <select> elements side by side using Bootstrap

The issue I am encountering is that these two select elements within the same control-group are being displayed vertically when I want them to be displayed horizontally. I attempted using inline-block in CSS, but there are other <div> elements with ...

Unable to play video using the play() method in Video.js player instance

I am trying to start playing a video.js player instance programmatically by using the play() method on it. The markup for the player is as follows: <video-js id ="some-player-id" src ="https://vjs.zencdn.net/v/oceans.mp4&quo ...

Updating a database with a loop of React Material UI toggle switches

I am trying to implement a material UI switch feature that can update the Active and De-Active status of users in the database directly from the Admin Panel. Currently, the database updates are functioning correctly when toggling the switches. However, th ...

When using setTimeout in NodeJS/Express, a TypeError is thrown stating that it cannot read the property 'client' as it is undefined

My nodejs express route is basic: app.get('/timeout', function (req, res) { setTimeout(() => { console.log('timeout'); }, 2000); res.send({ hello: "world" }); }); However, it's not functioning cor ...

What steps should I take to troubleshoot this particular gulp problem within my Laravel 5.2 project?

After running gulp from the terminal, everything appeared to be working properly. var gulp = require('gulp-help')(require('gulp')); var elixir = require('laravel-elixir'); const debug = require('gulp-debug'); /* | ...

Using ternary operators in a return statement is not effective when working with the react useState Hook

Struggling to make sense of my framework code and trying to refactor the business logic, I find myself in a state of confusion as things are not functioning as expected. Currently, I have successfully implemented a simple counter in React using the useStat ...

Is it possible to utilize personalized functionalities in the main.js file of the Firefox Addon SDK?

Why am I encountering difficulties accessing custom functions with the Firefox Addon SDK? In the code snippet provided below, whenever I click on context menu Sub Item 1, it does not work as intended; It is trying to access the custom function verifyTest( ...

Updating div using ajax leads to the checkbox losing its value

I have a small PHP-site feature that displays a list of members who attended a specific event. The feature includes a checkbox within a box, which interacts with a database to store information about the attendees. I want the box to update dynamically when ...

Issue with scrollIntoView in devices with a width lower than 1200px

In my Angular 5 project, I have a table where each row is generated dynamically using *ngFor and given an id based on the username. <tbody *ngFor="let User of FullTable; let i = index"> <tr id='{{User.username}}'> <th scope="r ...

Organize JSON data based on the timestamp

What is the most effective method for sorting them by timestamp using jquery or plain JavaScript? [{"userName":"sdfs","conversation":"jlkdsjflsf","timestamp":"2013-10-29T15:30:14.840Z"},{"userName":"sdfs","conversation":"\ndslfkjdslkfds","timestamp" ...

How can I retrieve the ClientID of a div element within an ASPX page using JavaScript?

Is there a way to retrieve the client id from a contentplaceholder in an aspx page without involving the master page? I understand that a div is not a control, but I am curious if there is a workaround. (Please note that the code displayed is not within th ...