Showing posts from March, 2013

ASP.NET User Control with Template Content user controls are great.  I use them all the time when working on .net websites.  I was working on a site using the ajax extender toolkit.  I created a panel that could be expanded collapsed with a button click.  I inserted a few into the site and liked them so much I made some more.  Well after the 7th panel it started getting tedious.  What a perfect place for a user control.  The problem was I needed to be able to place whatever custom content I wanted inside the panel.  After much searching around I wasn't finding what I wanted.  The answer it turns out is an user control with custom templates. Create a new user control for your site.  Mine is called CollapsiblePanel.  In the code behind for the page you need to add a new class MessageContainer that inherits from Control and implements the INamingContainer Interface .   Then in the user controls OnInit method you need to check for content and add it to your user control. using System; using

C++ convert char * to to wide string wstring

Often times when working with older code you find yourself staring at some old char* variables. I often find myself having to convert them to wide strings for unicode support (wstring). I created a handy function that makes this simple. wstring charToWideString( const char* src ) { return std::wstring( src, src + strlen(src) ); } Now simply call thus: wstring thus = charToWideString( "thus" ); Drop this function in a static class or header file and use it anywhere.

ASP.NET Create Javascript Alert on Server Side

Many times in you find yourself needing to create an alert on the client side but you're processing on the server side. The trick is to register a Javascript to the client from the server. I have found a nifty way of creating a class that will allow you to do this. public static class ClientMessageBox { public static void Show(string message, Control owner) { Page page = (owner as Page) ?? owner.Page; if (page == null) { return; } page.ClientScript.RegisterStartupScript(owner.GetType(), "ShowMessage", string.Format("<script type="text/javascript">;alert('{0}')</script>", message)); } } // Example of using class and method protected void Page_Load(object sender, EventArgs e) { ClientMessageBox.Show("Hello World", this); } You can now call ClientMessageBox.Show('text', this ); anywhere server side and get a