jQuery Validation plugin in ASP.NET Web Forms

You can checkout the rules add function, but basically here’s what you can do: jQuery(function() { // You can specify some validation options here but not rules and messages jQuery(‘form’).validate(); // Add a custom class to your name mangled input and add rules like this jQuery(‘.username’).rules(‘add’, { required: true, messages: { required: ‘Some custom message … Read more

ASP.NET Custom user control to add dynamically

What I have done is use the Page.LoadControl method in the Page_Init to add the custom user control to a place holder on the page. protected void Page_Init(object sender, EventArgs e) { //MyControl is the Custom User Control with a code behind file MyControl myControl = (MyControl)Page.LoadControl(“~/MyControl.ascx”); //UserControlHolder is a place holder on the aspx … Read more

Styling [duplicate]

The CSS way (base code found here): <html> <style type=”text/css”> div.fileinputs { position: relative; } div.fakefile { position: absolute; top: 0px; left: 0px; z-index: 1; } div.fakefile input[type=button] { /* enough width to completely overlap the real hidden file control */ cursor: pointer; width: 148px; } div.fileinputs input.file { position: relative; text-align: right; -moz-opacity:0 ; … Read more

Event Bubbling and MVP: ASP.NET

TLDR the code. Here’s how I would do it. You say there are 2 controls on the same page. So that can be served by a ContainerVM with references (members) of TimeVM and MonthVM. TimeVM updates a backing property ResultantDate whenever you do your thing. ContainerVM has subscribed to property-changed notifications for TimeVM.ResultantDate. Whenever it … Read more

Dropdownlist control with s for asp.net (webforms)?

I’ve used the standard control in the past, and just added a simple ControlAdapter for it that would override the default behavior so it could render <optgroup>s in certain places. This works great even if you have controls that don’t need the special behavior, because the additional feature doesn’t get in the way. Note that … Read more

How do I prevent users clicking a button twice?

If you simply disable the button then ASP.NET won’t post the form. Also you want to deal with client-side validation. Here’s my solution: <asp:Button runat=”server” ID=”btnSave” Text=”Save” OnClick=”btnSave_Click” OnClientClick=”if (!Page_ClientValidate()){ return false; } this.disabled = true; this.value=”Saving…”;” UseSubmitBehavior=”false” /> See @Dave Ward’s post for a description of UseSubmitBehavior. If you have multiple validation groups you’ll … Read more