All tutorials
Every tutorial on Postback Notes, grouped by section. Each one contains a complete example and links to the official documentation it relies on.
ASP.NET
- 'A potentially dangerous Request.Form value was detected' in ASP.NET
Why ASP.NET request validation rejects input containing HTML-like text, how to allow it safely for one field (ValidateRequestMode, Unvalidated) instead of disabling it everywhere, and the output encoding and sanitising you then need.
- 'Unable to serialize the session state' in ASP.NET: why it happens and how to fix it
The 'Unable to serialize the session state. In StateServer and SQLServer mode…' error explained: what out-of-process session state requires, marking classes [Serializable], NonSerialized fields, objects that can never be serialized, and storing keys instead of heavy objects.
- appSettings vs connectionStrings in web.config
The difference between the appSettings and connectionStrings sections of web.config: what each stores, how to read them with ConfigurationManager, provider names, release transforms, external files and encrypting sensitive sections.
- Auto-refresh an ASP.NET page every 10 seconds
Refresh an ASP.NET Web Forms page or part of it at a fixed interval: the Refresh header and meta refresh, an ASP.NET AJAX Timer with an UpdatePanel for partial refresh, and a lightweight fetch-based alternative, with notes on load and accessibility.
- Bind a GridView with ExecuteReader in ASP.NET (C#)
Fill an ASP.NET GridView straight from a SqlDataReader: the DataSource and DataBind sequence, why the connection must stay open while binding, loading into a DataTable or a list instead, formatting columns, and when paging requires a different approach.
- Bind an ASP.NET DropDownList to SQL Server data (C#)
Fill a DropDownList from a SQL Server table: DataTextField and DataValueField, adding a 'please choose' item with AppendDataBoundItems, binding only on the first load, reading the selection, and validating that a real item was chosen.
- Breadcrumbs in ASP.NET with the SiteMapPath control
Show a breadcrumb trail in ASP.NET Web Forms with SiteMapPath and Web.sitemap: setup in a master page, separators and templates, pages with query strings, accessible markup with nav and aria-current, and structured data for search engines.
- Call a JavaScript function from code-behind in ASP.NET (C#)
Run a JavaScript function after a postback from C#: ClientScript.RegisterStartupScript, ScriptManager.RegisterStartupScript inside UpdatePanels, passing server values safely with JSON encoding, and a data-attribute alternative that avoids generated script.
- Cascading Country, State and City DropDownLists in ASP.NET without a full page refresh
Build dependent Country, State and City DropDownLists in ASP.NET Web Forms backed by SQL Server: AutoPostBack and SelectedIndexChanged, resetting child lists, then wrapping the lists in an UpdatePanel so only the lists refresh, with notes on event validation and view state.
- Choosing hosting for an ASP.NET website: what to check before you pay
A vendor-neutral guide to hosting ASP.NET applications: Web Forms on Windows and IIS versus ASP.NET Core on Linux or Windows, shared hosting, VPS and cloud platforms, SQL Server options, the technical checklist, and how to test a host before migrating.
- Confirm message boxes in ASP.NET: OnClientClick and confirmations decided on the server
Ask 'Are you sure?' before a postback with OnClientClick and confirm(), set the message from code-behind, confirm buttons inside GridView rows, and handle the case where the server must ask for confirmation first (two-step postback with a hidden field).
- Connect to a Windows VPS or server with Remote Desktop
How to connect to a Windows Server VPS with Remote Desktop (RDP) from Windows, macOS and Linux, what to check when it fails, and the security measures an exposed RDP port needs: strong credentials, Network Level Authentication, firewall rules, VPN or gateway.
- Cross-page posting in ASP.NET: read the previous page's controls
Post a Web Forms page to another page with PostBackUrl, then read the source page's values through PreviousPage: FindControl, the strongly typed @PreviousPageType directive with public properties, IsCrossPagePostBack, and how it compares with Server.Transfer and the query string.
- Export GridView data to Excel, Word, CSV text and PDF in ASP.NET (C#)
Export the contents of an ASP.NET GridView: real .xlsx files with ClosedXML, CSV text with proper escaping, the old HTML-as-Excel/Word trick and its warning, PDF with an open-source library, and the VerifyRenderingInServerForm error explained.
- Get the connection string from web.config and connect to SQL Server in ASP.NET
Store a SQL Server connection string in web.config, read it with ConfigurationManager, open a SqlConnection safely with using, the common formats (Windows authentication, SQL login, LocalDB, Azure SQL), encryption settings, and connection errors explained.
- Get the selected row's data from a GridView in code-behind (C#)
Read the values of the row a user selects in an ASP.NET GridView: SelectedIndexChanged, SelectedRow cells versus DataKeys, values inside TemplateFields with FindControl, buttons with CommandArgument, and styling the selected row.
- GridView inline insert, edit, update and delete in ASP.NET (C#)
A complete Web Forms example that edits SQL Server data directly in a GridView: binding, edit and cancel, updating with parameters, deleting with confirmation, and adding new rows through the footer row, with the events explained in order.
- Handle multiple submit buttons in one ASP.NET MVC form
Three ways to know which button submitted an ASP.NET MVC form: a named button whose value binds to an action parameter, separate actions with the formaction attribute, and a custom ActionNameSelector attribute, with notes on validation and ASP.NET Core.
- How to bind an ASP.NET Repeater control (C#)
Bind a Repeater to SQL Server data: templates (Header, Item, AlternatingItem, Separator, Footer), Eval versus strongly typed Item binding, ItemDataBound for conditional output, ItemCommand for buttons, and an empty-data message.
- How to use the ASP.NET Menu control: static items, Web.sitemap and styling
The ASP.NET Web Forms Menu control explained with examples: static MenuItems, binding to Web.sitemap through a SiteMapDataSource, horizontal and vertical layouts, dynamic sub-menus, RenderingMode List with CSS, security trimming by role, and highlighting the current page.
- Insert, edit, update and delete records with a form and a GridView in ASP.NET (C#)
A simple CRUD page in ASP.NET Web Forms: a form above a GridView adds records, a Select button loads a row into the form for editing, Update and Delete work by primary key, all with parameterised ADO.NET commands.
- Keep GridView check boxes checked across pages in ASP.NET
When a paged GridView rebinds, check boxes on other pages are lost. Store the selected keys in ViewState before changing page, restore them after binding, and read the full selection on submit, with complete C# code.
- Paging a Repeater in ASP.NET: custom pager and the ListView/DataPager alternative
The Repeater has no paging and cannot use DataPager directly. Two working approaches: a custom pager with PagedDataSource and LinkButtons, and switching to a ListView with a DataPager, which keeps Repeater-style templates.
- Parser Error when deploying an ASP.NET application: causes and fixes
How to read the ASP.NET 'Parser Error' and 'Configuration Error' pages after a deployment, and fix the usual causes: Could not load type, wrong CodeBehind vs CodeFile, missing bin assemblies, application not configured in IIS, allowDefinition=MachineToApplication, duplicate config sections and framework version mismatches.
- Passing an ampersand (&) in a QueryString value in ASP.NET
Why a value like 'Tom & Jerry' gets cut at the ampersand in a URL, how to encode it with HttpUtility.UrlEncode or Uri.EscapeDataString in C# and encodeURIComponent in JavaScript, how ASP.NET decodes it, and the difference with HTML encoding of &.
- Passing multiple parameters in an ASP.NET QueryString (C#)
Build URLs with several query string parameters in ASP.NET Web Forms, encode values correctly with UrlEncode or HttpUtility.ParseQueryString, read and validate them with Request.QueryString, handle repeated keys, and avoid putting sensitive data in the URL.
- Read appSettings values from web.config in ASP.NET (C#)
Read appSettings keys with ConfigurationManager.AppSettings, convert them to numbers, booleans and lists with defaults, use them in markup with <%$ AppSettings %>, keep secrets out of source control, and what changing web.config does to a running site.
- Redirect to another page after a few seconds in ASP.NET
Send users to another URL after a delay: the Refresh header from C#, a meta refresh tag, a JavaScript countdown that shows the remaining seconds, and when a server-side 301 or 302 is the better choice.
- Session state vs ViewState in ASP.NET
Where Session and ViewState keep data, how long it lives, who can see it, what it costs, and which to choose for typical Web Forms needs, with code for both and the security settings that protect view state.
- Set an ASPX page's title, meta description and keywords dynamically
Set the title, meta description and meta keywords of an ASP.NET Web Forms page from code: Page.Title, Page.MetaDescription and Page.MetaKeywords, adding other meta and link tags with HtmlMeta, master page scenarios, and what search engines still use.
- Show a tooltip (title) on DropDownList items in ASP.NET
Add a title attribute to each item of an ASP.NET DropDownList from C#: ListItem.Attributes after data binding, why the attributes disappear after a postback and how to restore them, browser support for option tooltips, and better alternatives for long texts.
- Show an alert message box from code-behind in ASP.NET (C#)
Display a JavaScript alert after server-side processing in Web Forms: RegisterStartupScript with a safely encoded message, the UpdatePanel variant, why Response.Write breaks the page, and an accessible in-page message as the better alternative.
- The three ASP.NET programming models: Web Forms, MVC and Web Pages
How ASP.NET Web Forms, ASP.NET MVC and ASP.NET Web Pages (Razor) differ in structure, state handling, control over HTML and testability, where each stands today on .NET Framework, and how ASP.NET Core's Razor Pages, MVC and Blazor took over their roles.
- Upload files to a server folder and download them again in ASP.NET (C#)
A safe file upload and download page in ASP.NET Web Forms: the FileUpload control, size limits in maxRequestLength and maxAllowedContentLength, generated file names, extension allow-lists, storage outside the web root, listing files and streaming them back with the right headers.
- Validate the file extension when uploading files in ASP.NET
Allow only certain file types in an ASP.NET FileUpload: the accept attribute, a RegularExpressionValidator and a JavaScript check in the browser, the authoritative server-side allow-list, and checking file signatures for extra safety.
- Web Site project vs Web Application project in Visual Studio
The two ways Visual Studio organises an ASP.NET Web Forms project: dynamic compilation and CodeFile in a Web Site, a project file and a single compiled assembly with CodeBehind in a Web Application, with deployment differences and how to choose or convert.
C# & ADO.NET
- Convert a SqlDataReader to a DataTable with DataTable.Load (C#)
Use DataTable.Load to copy the rows of a SqlDataReader into a DataTable: basic usage, what happens to the reader, LoadOption, schema and constraint errors, several result sets, and when this beats SqlDataAdapter.Fill.
- DataSet vs DataTable in ADO.NET
What a DataTable and a DataSet each hold, how to fill them with a SqlDataAdapter, relations and constraints between tables, memory and serialization costs, and when a typed list or a data reader is the better choice.
- DataSet, DataReader, DataAdapter and DataView: what each ADO.NET class does
The four ADO.NET classes that confuse beginners, explained by role: the connected DataReader, the disconnected DataSet, the DataAdapter that moves data between them and the database, and the DataView that filters and sorts a DataTable, with code for each.
- ExecuteReader vs ExecuteNonQuery vs ExecuteScalar in ADO.NET
The three SqlCommand execution methods compared: what each returns, when to use it, how row counts behave with SET NOCOUNT and triggers, reading identity values with ExecuteScalar or OUTPUT, null handling, and their async versions.
- Export a folder's file list to CSV or Excel in C#
Collect file names, sizes and dates from a folder with DirectoryInfo and export them to a CSV file Excel opens correctly (encoding, separators, quoting, invariant dates) or to a real .xlsx, from a console app or an ASP.NET page.
- How to deserialize an XML document into C# objects
Turn XML into C# objects with XmlSerializer: matching classes with XmlRoot, XmlElement, XmlAttribute and XmlArray, reading from a file, a string or an uploaded stream, namespaces, generating classes with xsd.exe, common InvalidOperationException causes and safe parsing of untrusted XML.
- Import CSV or Excel data into SQL Server from ASP.NET (SqlBulkCopy and BULK INSERT)
Load an uploaded CSV file into SQL Server: parsing with TextFieldParser, validating rows into a DataTable, writing them with SqlBulkCopy and column mappings, a staging table pattern, the T-SQL BULK INSERT alternative and reading Excel files.
- List all files in a folder and its subfolders in C#
Get every file under a directory recursively in C#: Directory.GetFiles versus EnumerateFiles, SearchOption.AllDirectories, EnumerationOptions to skip inaccessible folders, filtering by extension, and listing the result on an ASP.NET page.
- Pass a DataTable as a table-valued parameter to a SQL Server stored procedure
Send many rows to SQL Server in one call: create a user-defined table type, a stored procedure with a READONLY table parameter, and pass a DataTable (or IEnumerable of SqlDataRecord) from C# with SqlDbType.Structured.
- Send a GridView (all rows or selected rows) by e-mail in ASP.NET (C#)
E-mail the contents of an ASP.NET GridView: build an HTML table from the data with inline styles, include only the rows the user ticked, send it with SmtpClient and MailMessage, and avoid the RenderControl pitfalls.
- Send an HTML page or template as an e-mail in ASP.NET (C#)
Send a newsletter-style HTML e-mail from ASP.NET: an HTML template file with placeholders, encoding values, a plain-text alternative, embedded images with LinkedResource, and why rendering a live .aspx page into an e-mail causes problems.
- Sending a test e-mail from ASP.NET through Gmail's SMTP server (C#)
Send mail from an ASP.NET Web Forms page with SmtpClient and Gmail: smtp.gmail.com on port 587 with STARTTLS, app passwords now that Google no longer accepts plain passwords from apps, web.config mailSettings, TLS 1.2, attachments, common errors, and why to use a transactional service in production.
- Split a date string into day, month and year in C# and JavaScript
Extract day, month and year from a date string reliably: DateTime.ParseExact and TryParseExact with an explicit format and culture in C#, why String.Split alone is fragile, DateOnly, and the equivalent in JavaScript.
- SqlCommand.ExecuteNonQuery example in ASP.NET (C#)
A working ExecuteNonQuery example: inserting, updating and deleting SQL Server rows from a Web Forms page with parameters, reading the rows-affected count, running a stored procedure with an output parameter, and wrapping several commands in a transaction.
- SqlCommand.ExecuteReader example in ASP.NET (C#)
Read SQL Server rows with SqlCommand.ExecuteReader in a Web Forms page: looping with Read, typed getters and NULL checks, building HTML safely, reading several result sets with NextResult, and CommandBehavior options.
- SqlCommand.ExecuteScalar example in ASP.NET (C#)
ExecuteScalar in practice: counting rows, checking whether a user name is taken, reading a single setting, returning a new identity value, and handling null, DBNull and type conversions correctly.
OOP & concepts
- 100 interview questions on ASP.NET, C#, SQL Server and OOP, with short answers
One hundred questions that come up in .NET developer interviews, grouped by topic, each with a short, accurate answer: OOP, C# language, ASP.NET Web Forms and MVC, ADO.NET, SQL Server, web basics and security.
- C vs C++: the main differences, from an object-oriented point of view
How C++ extends C with classes, encapsulation, inheritance, polymorphism, templates, references, exceptions, RAII and the standard library, what stays the same, and how both compare with C#.
- Java vs .NET: how the two platforms compare
A factual comparison of the Java platform and .NET: runtimes and bytecode, languages, open-source status and governance, cross-platform support, web frameworks, tooling, and what usually decides the choice for a team.
- OOP concepts in C# with examples: classes, encapsulation, inheritance, polymorphism and abstraction
Object-oriented programming explained with one running C# example: classes and objects, encapsulation with properties, inheritance and constructors, virtual and override, abstract classes and interfaces, plus composition and the mistakes interviewers ask about.
- SQL injection: what it is and how to prevent it in ASP.NET and SQL Server
How SQL injection works, a vulnerable ADO.NET login query and how it is exploited, and the defences that actually work in C# and SQL Server: parameterised commands, safe stored procedures and sp_executesql, allow-lists for identifiers and least privilege.
- string vs String in C#: is there any difference?
string is the C# keyword alias for System.String: the same type, same methods, same compiled code. Where the two spellings differ in practice (using directives, nameof, style rules), the other built-in aliases, and the common naming conventions.
- string vs StringBuilder in C#: when to use which
Why C# strings are immutable, what repeated concatenation costs, how StringBuilder avoids it, when plain concatenation or string.Join is just as good, capacity, and examples from ASP.NET such as building HTML and CSV.
jQuery & JavaScript
- 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.
- 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.
- 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 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.
- 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.
- 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.
HTML & CSS
- CSS3 tooltip: show and hide hint text with a transition
An accessible tooltip built with HTML and CSS3 transitions: positioning with absolute and transform, an arrow drawn with a pseudo-element, showing on hover and keyboard focus, aria-describedby, the Escape key, and using it next to ASP.NET form fields.
- Fade in and fade out with a CSS3 transition
Build fade-in and fade-out effects with the CSS transition property: opacity with visibility so hidden elements stop catching clicks, hover and class-toggle versions, timing functions, fading on page load with keyframes, and respecting prefers-reduced-motion.
- Fixing an embedded Facebook box that overlaps or overflows your layout
The old Facebook Like Box was replaced by the Page Plugin. How to embed the Page Plugin responsively, why embedded social widgets overlap menus or overflow narrow columns, and the CSS (width, overflow, z-index, stacking contexts) that fixes it.
- Highlight a GridView row on mouse hover with CSS3 (or jQuery)
Highlight the row under the mouse in an ASP.NET GridView: the one-line CSS :hover rule with a transition, keyboard-friendly focus-within highlighting, zebra striping, the older jQuery hover approach, and why onmouseover attributes from RowDataBound are no longer needed.
- The HTML frameset tag, with an example, and what to use instead
How the HTML frameset and frame elements divided a browser window, a complete working example with rows, cols, name and target, why frameset is obsolete in HTML5, and the modern replacements: iframe, CSS grid layouts and server-side includes or master pages.