Rebind my ASP.Net script using JavaScript after a postback

Upon reviewing this article, I have come to understand that when using updatepanel for postback, the javascript bindings are lost.

The issue I am facing is that my javascript code resides in a file called jscolor.js. The connection between my asp page and the script seems fine:

<script src="../../assets/js/jscolor.js"></script>

The class name of my textbox is "jscolor" as per the demo on the website

<asp:TextBox Class="jscolor" ID="Couleur_1" runat="server"></asp:TextBox>

After a postback, I need to rebind my script, but most demonstrations I've seen involve click functions rather than this situation.

For reference, the jscolor script starts like this:

if (!window.jscolor) { window.jscolor = (function () { ...

Thank you in advance, J-E

Answer №1

To update the color of the TextBoxes, simply call a function like this:

if (Page.IsPostBack)
{
    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "rebindColor", "if (!window.jscolor) { window.jscolor = (function () {", true);
}

You can also create a separate function for easier maintenance, which will be triggered by the ScriptManager.

ScriptManager.RegisterStartupScript(Page, Page.GetType(), "rebindColor", "rebindColor()", true);

Finally, include the following script in your .aspx page:

<script type="text/javascript>
    function rebindColor() {
        if (!window.jscolor) { window.jscolor = (function () {...

        }
</script>

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 require the ability to retrieve only the data from a UI grid column, specifically based on the column name selected

I need help with my angularjs application that utilizes Ui grid. There is an external dropdown menu located outside of the ui grid, which lists all the column names in the grid. I want to be able to select a specific column name from this dropdown and retr ...

When you try to create a popover, a cautionary message pops up indicating that $tooltip is no longer supported. It is

I need help with creating a popover that appears when hovering over an anchor tag. Here is the code I am using: angular: 1.4.2 ui-bootstrap :0.14.2 <div class="row" ng-repeat="endorsement in endorsements| filter: {category:categorySelected}"> &l ...

Ways to obtain the output of an If/Else statement

It seems like I might be missing something, but I am unsure of how to extract the result from an else-if statement. Take this code snippet that I've been working on for example: In this scenario, the output would read "It's warm!", and what I wa ...

What could be causing the Logical Or to fail in my function?

How can I adjust the following sample code to check for not only empty keys but also null and undefined? I attempted: (obj[key] !== '' || obj[key] !== null || (obj[key] !== undefined) However, that approach caused issues and did not function c ...

Transferring data through button click in a strongly-typed view to a different controller

I am facing an issue with my strongly-typed view that is bound to userController. It displays the User with specific Roles and has a dropdown list below it containing all the Roles along with a submit button. My goal is to assign a new Role to the User by ...

Creating a copy of a div using jQuery's Clone method

I need help figuring out how to clone a div without copying its value. I've attempted various methods, but they all seem to include the value in the cloned element. This is the jQuery function I am currently using: $('#add_more').click(fu ...

Using jQuery to extract the value of 'selectedValue' from RadDropDownList

My goal is clearly stated in the title. Within my '#dropdown' control, the value currently looks like this: value="{"enabled":true,"logEntries":[],"selectedIndex":8,"selectedText":"Option2","selectedValue":"250"}" I am specifically interested ...

Leverage AJAX for real-time Django Model updates

Seeking insights on how to effortlessly update a Django model through AJAX without reloading the page or requiring user input for saving. Various tutorials address fetching data from Django models using AJAX, yet resources on updating models remain scarce. ...

Oops! Remember to always `await server.start()` first before using `server.createHandler()` in next.js

An error is popping up when I attempt to check the functionality of Apollo GraphQL. Error: You must await server.start() before calling server.createHandler() Note: Although there is a similar question regarding this issue, it is specific to Express. Error ...

A guide on extracting attribute values with special characters in HTML

I have a requirement where I need to extract an ID from a JSON response. This ID is in the format "TICKET NUMBER (TK)". In the HTML component, there is an attribute called CI which has the same value as the ID. However, when I try to access any attribute ...

FireFox is experiencing issues with jQuery AJAX functionality

I'm encountering an issue with my AJAX request on my website (not crossdomain). Here is the code that I am currently using: $("#submit").click(function(e){ var nameW = $("#name").val(); var teamValue = $("#team").val(); $.aja ...

Updating a User's Role in Asp.net Identity Without Logging Out

On my page, when a logged-in user takes an action, I adjust their role by executing this code: var userStore = new UserStore<IdentityUser>(); var manager = new UserManager<IdentityUser>(userStore); IdentityUser user = manager.Find ...

Best practices for incorporating JavaScript into Angular applications

I am looking to integrate a JavaScript library into my Angular application. After researching various methods, I have decided to incorporate the library found at . I was hoping to create a module named 'plot-function' that would offer a function ...

How can I identify a pattern in JavaScript that may include a certain character but cannot end with it using regex?

I am a beginner in the world of regular expressions. Despite my efforts to find a solution for my specific case, I have not been successful. I have tested several ideas that I came across, but none of them have worked for me. I have a unique repetitive pa ...

Substitute "Basic Authentication" with "Form Authentication"

Is there a way in W20 to switch from using "Basic Authentication" to "Form Authentication"? The current documentation mentions only the use of "basicAuth" and does not provide information on implementing form authentication. Our app is built with Angular ...

Utilizing the URLSearchParams object for fetching data in React

I've implemented a custom hook named useFetch: const useFetch = (url: string, method = 'get', queryParams: any) => { useEffect(() => { let queryString = url; if (queryParams) { queryString += '?' + queryParam ...

JavaScript decimal validation not functioning as intended

Hey everyone! I've created a script that restricts textboxes to allow only decimal numbers. Take a look at the code snippet below: function onlyDecimal(evt) { if (!(evt.keyCode == 46 || (evt.keyCode >= 48 && evt.keyCode <= 57))) ...

merge two structures to create a unified entity

I have been searching in vain, can you please advise me on how to combine these two simple forms into one? I want it to be like a box with a select option and a button. The challenge for me is merging the two different actions, ".asp", into one script fo ...

angularjs determining the appropriate time to utilize a directive

I have been delving into JavaScript and AngularJS for approximately a month now, but I still find myself unsure of when to use directives. For example: I am looking to display appointments in a table with the date as the table header. I envision having bu ...

Validation check for data imported from an Oracle database

I am facing challenges in checking if the database has already imported data. I have shared my code for the backend, middle layer, and front end below. Can someone please review it and point out any mistakes? Thank you for your assistance. Mike The follo ...