Archive for the 'web' Category
How to instantiate templates (properly)
Something for myself to bookmark. Here is a really good article describing the right way to instantiate templates in asp.net controls.
Every time a control is added to a parent control the child control will immediately “catch up” to the lifecycle point of the parent control. The control lifecycle includes the familiar Init, Load, PreRender, and a number of other lifecycle stages related to state management. When a template is instantiated through a call to InstantiateIn, all that happens (typically) is that the controls in the template are instantiated one by one, and added to the container that you passed in to InstantiateIn, again one by one.
How to instantiate templates (properly)
I also subscribed to the blog and waiting for more good articles.
No commentsHowTo - CompositeControl with a TextBox and a bunch of Validators
Here is an example of how I create composite controls in small server control library. It is pretty handy. With controls like this you can say something like this:
<csc:textbox id=”customServerControl1″ minlength=”4″ maxlength=”10″ required=”true” runat=”server” />
And that’s it! The composite control will automatically add the required validators and will create appropriate error messages!
Here is the source code:
using System; using System.Security.Permissions; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace SashaSydoruk.Web.UI.WebControls { [AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)] [ToolboxData("< {0}:textbox required=\"false\" runat=\"server\" />")] [ValidationProperty("Text")] public class TextBox : CompositeControl { protected System.Web.UI.WebControls.TextBox _textBox = null; protected RequiredFieldValidator _reqValidator = null; protected RegularExpressionValidator _regExValidator = null; protected TextBoxLengthValidator _lengthValidator = null; protected string _regExValidatorErrorMessage = string.Empty; #region Constructors public TextBox() { EnsureChildControls(); } #endregion #region Error Messages public const string REQUIRED = “is a required field.”; public const string REGEX = “is invalid.”; public const string LENGTH = “length has to be {0} to {1} characters long”; #endregion #region Public Properties public System.Web.UI.WebControls.TextBox InnerTextBox { get { return _textBox; } } public RequiredFieldValidator InnerRequiredFieldValidator { get { return _reqValidator; } } public RegularExpressionValidator InnerRegularExpressionValidator { get { return _regExValidator; } } public TextBoxLengthValidator InnerTextBoxLengthValidator { get { return _lengthValidator; } } public TextBoxMode TextMode { get { return _textBox.TextMode; } set { _textBox.TextMode = value; } } public bool ReadOnly { get { object o = ViewState["ReadOnly"]; if(o == null) { return false; } else { return bool.Parse(o.ToString()); } } set { ViewState["ReadOnly"] = value; } } public int MaxLength { get { return _lengthValidator.MaximumLength; } set { _lengthValidator.MaximumLength = value; SetupValidators(); } } public int MinLength { get { return _lengthValidator.MinimumLength; } set { _lengthValidator.MinimumLength = value; SetupValidators(); } } public string RegularExpression { get { return _regExValidator.ValidationExpression; } set { _regExValidator.ValidationExpression = value; SetupValidators(); } } public string DisplayName { get { object o = ViewState["DisplayName"]; if(o == null) { return string.Empty; } else { return o.ToString(); } } set { ViewState["DisplayName"] = value; SetupValidators(); } } public bool Required { get { return _reqValidator.Visible; } set { _reqValidator.Visible = value; SetupValidators(); } } public virtual string Text { get { return _textBox.Text; } set { _textBox.Text = value; } } #endregion protected override void OnInit(EventArgs e) { EnsureChildControls(); base.OnInit(e); } protected override void Render(HtmlTextWriter writer) { _textBox.Width = Width; _textBox.Height = Height; _textBox.RenderControl(writer); _reqValidator.RenderControl(writer); _lengthValidator.RenderControl(writer); _regExValidator.RenderControl(writer); } protected override void CreateChildControls() { Controls.Clear(); _textBox = new System.Web.UI.WebControls.TextBox(); _textBox.ID = “textBox”; Controls.Add(_textBox); //Add required validator _reqValidator = new RequiredFieldValidator(); Controls.Add(_reqValidator); //Add length validator _lengthValidator = new TextBoxLengthValidator(); Controls.Add(_lengthValidator); //Add RegularExpression validator _regExValidator = new RegularExpressionValidator(); Controls.Add(_regExValidator); if(Width.Value == 0) { _textBox.Width = Unit.Pixel(170); } Required = false; SetupValidators(); } private void SetupValidators() { _reqValidator.Display = ValidatorDisplay.None; _reqValidator.ControlToValidate = _textBox.ID; _lengthValidator.Display = ValidatorDisplay.None; _lengthValidator.ControlToValidate = _textBox.ID; _regExValidator.Display = ValidatorDisplay.None; _regExValidator.ControlToValidate = _textBox.ID; if(MaxLength > 0) { _textBox.MaxLength = MaxLength; } _lengthValidator.Visible = (MaxLength > 0 || MinLength > 0); _regExValidator.Visible = RegularExpression.Length > 0; _reqValidator.ErrorMessage = DisplayName + ” “ + REQUIRED; if(MinLength == 0 && MaxLength > 0) { _lengthValidator.ErrorMessage = DisplayName + ” “ + string.Format(“is too long. {0} characters max.”, MaxLength); } else if(MinLength > 0 && MaxLength == 0) { _lengthValidator.ErrorMessage = DisplayName + ” “ + string.Format(“is too short. {0} characters min.”, MinLength); } else if(MinLength > 0 && MaxLength > 0) { _lengthValidator.ErrorMessage = DisplayName + ” “ + string.Format(“has to be {0} to {1} characters long.”, MinLength, MaxLength); } else if(MinLength > 0 && MaxLength > 0 && MinLength == MaxLength) { _lengthValidator.ErrorMessage = DisplayName + ” “ + string.Format(“has to be {0} characters long.”, MinLength); } _regExValidator.ErrorMessage = DisplayName + ” “ + REGEX; } } }
Windows Live Writer Error
I keep getting the following error while editing my blog settings. Does anyone know solution to this?
—————————
Unexpected Error Occurred
—————————
An unexpected error occurred while attempting to detect weblog settings:
Unable to cast COM object of type ‘mshtml.HTMLMetaElementClass’ to interface type ‘mshtml.IHTMLElement’. This operation failed because the QueryInterface call on the COM component for the interface with IID ‘{3050F1FF-98B5-11CF-BB82-00AA00BDCE0B}’ failed due to the following error: No such interface supported (Exception from HRESULT: 0×80004002 (E_NOINTERFACE)).
—————————
OK
—————————
FormsAuthentication.SetAuthCookie does not work the same way in ASP.NET 2.0
No commentsObviously I missed the boat somewhere along the line. I realized today that I’ve never used FormsAuthentication in an ASP.NET v2.0 application before. As it turns out, it doesn’t work the same as it used to.
Prototype 1.5 was released. And now it has documentation and a brand new site!
Wow, what a day… New Rails and new Prototype are out. The new website for Prototype looks really nice. I can’t wait to dive into the documentation and see what’s new!
It also looks like new Script.aculo.us is on the way too.
Future looks bright!
No commentsRuby On Rails 1.2 is out! Yay!
Get out your party balloons and funny hats because we’re there, baby. Yes, sire, Rails 1.2 is finally available in all it’s glory. It took a little longer than we initially anticipated to get everything lined up (and even then we had a tiny snag that bumped us straight from 1.2.0 to 1.2.1 before this announcement even had time to be written).
Rails 1.2: REST admiration, HTTP lovefest, and UTF-8 celebrations
No commentsRuby In Steel Developer Announced
No commentsSapphireSteel Software today formally announced Ruby In Steel Developer – the only professional Ruby programming environment for Microsoft’s Visual Studio 2005.
Ruby In Steel Developer provides a full suite of editing and debugging tools for Ruby and Ruby On Rails (‘Rails’) developers. Product highlights include:
Editing
Ruby and Rails (RHTML) code coloring
Ruby and Rails code folding/collapsing
Smart Indenting and code formatting
Ruby auto-expand snippets
Debugging
Ultra-fast integrated debugger
Step-Into/Step-Over/Step-Out tracing
‘Drill-down’ watch variables
Interactive ‘run and debug’ console
IntelliSense
Accurate (by class and scope) member completion
Parameter completion tooltips
Class and method documentation in tooltips
Code navigation drop-down combos over the editor
Ruby On Rails
Import Existing Ruby On Rails Projects
Rails Toolbar and script-runner dialogs
RHTML / HTML switchable editor
One-click Rails Debugger
A complete feature list can be found on the SapphireSteel web site:
Feature List
Scott Hanselman’s - “Language Extensibility” podcast
So, just as I was about to complain about how Scott Hanselman got me hooked on his I-can-stop-listening-to-this-podcast-any-time-I-want-I-just-don’t-want-to-right-now aka Hanselminutes and then left for his vacation and left me high and dry, desperately craving the sweet embrace of the new Hanselminutes, I noticed the new entry on my RSS reader in uTorrent.
There is no way – I thought to myself. He just came back from Africa. He did have enough time to come up with a new podcast. Must be something not very good…
But good it was. In fact, it was awesome. In his new podcast “Language Extensibility”, Scott talks about the future of IronPython and ASP.NET. This subject interested for quite a long time now. My interest was initially sparked by this white paper and this blog post. I tried to look for more information but came up with nothing.
Before you start with the “Language Extensibility”, I would strongly recommend listening to “Dynamic vs Compiled Languages” first, because it provides a lot of useful information that feeds nicely into the following podcast.
Once again, Scott proved that he knows his stuff and if you want to know what is happening in .Net world, his podcast is the podcast to listen to.
Thank you Scott!
1 commentXSS through PDF files
This is just great. You can now hack websites with XSS in PDF files. Adobe Reader will executed any JavaScript passed to it through a query string. Here is a working example:
http://www.example.com/document.pdf#whatever_name_you_want=javascript:alert(document.cookie);
If you replace www.example.com and document.pdf with valid samples and click on the link, the browser will pop up, load the specified file from the specified site and show you your cookies for that site.
Adobe Reader v8.0 is not affected. Also, this does not work on some Win XP SP2 + IE 7.0 systems.
Found via Alek Levin.
No comments