jQuery & JavaScript
Reading and changing Web Forms controls from the browser: client IDs, validation, events, effects and small DOM utilities.
- Call a server-side C# method from jQuery AJAX in ASP.NET Web Forms
Call a static [WebMethod] page method from jQuery without a postback: the C# method, the $.ajax call with JSON content type, the 'd' wrapper in the response, error handling, friendly URLs, security (authentication and anti-forgery), and alternatives.
- Change an input's background colour on focus and blur (jQuery and CSS)
Highlight the active form field in an ASP.NET page: the jQuery focus and blur approach, the simpler CSS :focus and :focus-visible rules that need no script, highlighting the whole field group with :focus-within, and keeping the focus outline accessible.
- Check or uncheck all CheckBoxes in an ASP.NET GridView with jQuery
A header 'select all' check box for an ASP.NET GridView: TemplateField markup, jQuery that checks every row, keeps the header in sync and shows the indeterminate state, plus reading the checked rows on the server.
- Convert a JSON date like /Date(1700000000000)/ to a local date in JavaScript
Why ASP.NET page methods and older services return dates as /Date(ticks)/, how to parse that format and ISO 8601 strings into JavaScript Date objects, display them in the visitor's time zone, and how to make the server send ISO 8601 instead.
- Disable the submit button after the form is submitted (jQuery and ASP.NET)
Prevent double submissions in an ASP.NET Web Forms page: disabling the button after submit without losing its click event, respecting client-side validation, ASP.NET's UseSubmitBehavior, and the server-side guard you still need.
- Enable or disable an ASP.NET TextBox on a button click with jQuery
Toggle an ASP.NET TextBox between enabled and disabled from a button click using jQuery's prop(), without an unwanted postback, and understand what disabled, readonly and the server-side Enabled property each do to the posted value.
- Get and set an ASP.NET TextBox value with JavaScript
How to read and change the text of an ASP.NET Web Forms TextBox from plain JavaScript: finding the rendered id with ClientID and ClientIDMode, the value property, multiline boxes, read-only and disabled boxes, and what the server sees after a postback.
- Get and set an ASP.NET TextBox value with jQuery
Using jQuery's val() to read and write an ASP.NET Web Forms TextBox: selectors that survive ClientID rewriting, reacting to input, setting values in GridView rows, and keeping the posted value on the server.
- Get the hash (#fragment) of the current URL in JavaScript
Read and change the fragment part of the page URL with location.hash, decode it, react to changes with the hashchange event, and know why the server (and ASP.NET code) never sees it.
- Get the mouse cursor position in JavaScript and jQuery
Read the pointer position from mouse events: clientX/Y, pageX/Y, screenX/Y and offsetX/Y explained, the position relative to an element with getBoundingClientRect, pointer events for touch and pen, and a small follow-the-cursor tooltip.
- Get the selected value or text of an ASP.NET DropDownList with JavaScript or jQuery
Read the value and the visible text of the selected item of an ASP.NET DropDownList in the browser, with plain JavaScript and with jQuery, react to the change event, handle the placeholder item and multi-select ListBoxes.
- Highlight a GridView row when its check box is ticked (jQuery and CSS)
Visually mark the selected rows of an ASP.NET GridView: toggling a CSS class from the check box change event with jQuery, keeping the highlight after postback with RowDataBound, clicking anywhere on the row, and a CSS-only :has() alternative.
- Preview an image before uploading (JavaScript, jQuery and ASP.NET FileUpload)
Show a thumbnail of the image a user selects before the form is submitted: URL.createObjectURL or FileReader, a jQuery version for an ASP.NET FileUpload, checking type and size on the client, multiple previews, and the server-side checks that must follow.
- Print an ASP.NET GridView on a button click with JavaScript
Print only the GridView, not the whole page: a print stylesheet with @media print, the window.print() button, printing all pages of a paged grid, repeating table headers, and the popup-window technique from older tutorials.
- Read GridView row values and HiddenFields on the client with jQuery
Get the values of a clicked or selected GridView row in the browser with jQuery: rendered table structure, HiddenFields and data attributes per row, event delegation, and passing the result to a dialog or back to the server.
- Read a QueryString value in the browser (JavaScript and jQuery)
Read query string parameters on the client with URLSearchParams, handle missing and repeated keys and encoding, the older regular-expression helper used with jQuery, and why the server must still validate the same values.
- Redirect to a URL on a button click in ASP.NET (JavaScript, jQuery or server-side)
Send the user to another page when a button is clicked: Response.Redirect and PostBackUrl on the server, OnClientClick and location.assign without a postback, a jQuery handler, opening in a new tab, and when a plain link is the right choice.
- Set an ASP.NET DropDownList's selected value or text with JavaScript and jQuery
Select an item of an ASP.NET DropDownList from the browser by value or by visible text, with plain JavaScript and with jQuery, fire AutoPostBack when needed, and avoid event validation and 'multiple items selected' errors on the server.
- Show the visitor's local time and a live clock with JavaScript (and jQuery)
Display the computer's current local date and time on an ASP.NET page with JavaScript's Date and Intl.DateTimeFormat, turn it into a live clock updated every second, a jQuery version, and why server time and client time differ.
- Split a string into an array in JavaScript (with jQuery helpers)
JavaScript's String.prototype.split explained (there is no jQuery split function): separators, limits, regular expressions, trimming and removing empty entries, iterating with $.each or forEach, and splitting values read from ASP.NET controls.
- Validate an ASP.NET CheckBoxList with JavaScript or jQuery (at least one, at most N)
RequiredFieldValidator does not work with CheckBoxList. Validate 'at least one' or 'at most three' boxes with a CustomValidator: client function in plain JavaScript or jQuery, the matching server-side check, and the rendered markup explained.
- Validate an ASP.NET DropDownList (JavaScript, jQuery and validators)
Make sure the user picked a real item in a DropDownList: RequiredFieldValidator with InitialValue, a CustomValidator with a JavaScript or jQuery client function for extra rules, and the server-side check.
- Validate an ASP.NET RadioButtonList (validators, JavaScript and jQuery)
Require a choice in a RadioButtonList: RequiredFieldValidator works directly, reading the selected value with plain JavaScript or jQuery for custom rules, the rendered name attribute, and the server-side check.
- jQuery fading effects: fadeIn, fadeOut, fadeTo and fadeToggle
The four jQuery fade methods with working examples: durations and easing, callbacks and promises, chaining and the animation queue, stop() to avoid build-up, using them on ASP.NET panels, and when CSS transitions are the better tool.