![]() |
|
[C#] C# CustomValidator for valid DateTime - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [C#] C# CustomValidator for valid DateTime (/showthread.php?tid=815484) |
C# CustomValidator for valid DateTime - ShadowCloud - Nov 13, 2010 Hi Guys I wasted quite a bit of time on this, so hopefully it will assist someone else: Add a custom validator and on the properties window just set the ID and ControlToValidate Then double click and add: Code Boolean valid = new Boolean();Now we need to write the ValidateDateTime function Code protected Boolean ValidateDateTime(Boolean valid, object source)This will work as long as you are validating a textbox. The ID of the validator as well as the textbox is dynamically calculated (from source and source.ControlToValidate so there is no need to alter it to make it work :) ) BTW: Here is the markup for an actual custom validator (which uses the above code) Code <asp:CustomValidator ID="ControlID" runat="server" You can also reuse this code for all the validators on the page. |