Welcome To Snipplr


Everyone's Recent C# Snippets



Since an asynchronous method is usually one you call and then it invokes a callback when it is finished, it is not obvious how to test such a method in a definite manner. In the method described at the above URL, the author uses .NET's System.Threadi...
1 1131 posted 15 years ago by pckujawa
*save as proxy.asxh and put it in your IIS virtual directory *consider using other methods to circumvent XSS: JSONP, dojox.io.xhrWindowNamePlugin, etc.
0 766 posted 15 years ago by stoyan
*IE7 sometimes complains that a JavaScript script is running too slow and asks the user whether they want to terminate it or continue. *To get rid of this annoying popup a few changes need to be made to the registry. *ref: http://www.itwriting.com...
0 844 posted 15 years ago by stoyan
When I'm running unit tests, I find it very annoying to have to check equality within loops when I've got two collections of data. I know of no built-in way (let me know if there is one) [Edit: [CollectionAssert](http://msdn.microsoft.com/en-us/libra...
0 908 posted 15 years ago by pckujawa
Displaying values as hex in a PropertyGrid by using a TypeConverter class. The TypeConverter class is assigned as a property to the PropertyGrid's data element. Consider improving by making the UInt32HexTypeConverter a generic/template as in HexTy...
0 1566 posted 15 years ago by jimfred
3 2011 posted 15 years ago by pckujawa
Stupidly simple -- just one pitfall: class to be bound must have Get/Set methods for reflection to discover. Which is annoying when it comes to client side classes auto generated from WSDL.
0 920 posted 15 years ago by rengber
0 733 posted 15 years ago by beresovskiy
Bind the DropDownList like normal (set DataSourceID, DataTextField, DataValueField), and <%BIND%> the SelectedValue field. AutoPostBack should be enabled. In the OnSelectedIndexChanged:
0 965 posted 15 years ago by jink
Use this code to pull a DotNetNuke URL from a tab name. We use this to replace "?tabname=blah" type URLs which do NOT transfer language info.
0 990 posted 15 years ago by jink
Basic example of calling a web service from code using GET. You can pass parameters in as query vars. Assumes return type of service is "String". Example return xml: <?xml> <string>US</string> @SNIPPLR TEAM: Please let me put xml at...
3 1327 posted 15 years ago by jasonseney
Essentially, you need to tell Visual Studio to generate an XML file with documentation, then use a separate tool to create a help file (usually .chm) out of that XML file. The tool to use is MS's Sandcastle. You'll also want a GUI for Sandcastle, whi...
0 1042 posted 15 years ago by pckujawa
Call with the path of any javascript you want to load into the HEAD of the ASPX page.
1 1279 posted 15 years ago by jink
Returns the postback sender ID. This is usually a button ID from a form that caused a post back.
0 885 posted 15 years ago by jink
Here are some example string formats. As I discover more I will add them here.
6 892 posted 15 years ago by stewshack
This is how I read a file using C#.
3 876 posted 15 years ago by stewshack
For a discussion of .NET events best-practices, see [Roy Osherove's blog post](http://weblogs.asp.net/rosherove/articles/DefensiveEventPublishing.aspx) and [this post](http://blogs.msdn.com/ericlippert/archive/2009/04/29/events-and-races.aspx). Be su...
0 929 posted 15 years ago by pckujawa
## Markup ## _Using square [ ] brackets for compatibility with Snipplr comment form_ [asp:PlaceHolder ID="StuffHolder" runat="server" ] <p>Some stuff in here</p> [/asp:PlaceHolder] ## Code Behind ## HtmlAttr[] attribu...
1 1233 posted 15 years ago by jasonseney
Say that you have a collection of objects empty but for IDs. You want to do a foreach loop through those objects and lookup detail one at a time. Unfortunately, in the foreach, you can't replace the references, you can only copy the new detail...
1 1099 posted 15 years ago by rengber
Append html to a div tag (using System.Web.UI.HtmlControls)
1 1380 posted 15 years ago by hobeau
This is an example piece of code that will load a SubSonic collection into the "col1" object. The collection class is told to look for the column "VendorId" in the products table and pull it based based on the matching supplied vendorId.
0 731 posted 15 years ago by mordecaix7
1 1584 posted 15 years ago by Unsafe
Sometimes you may need a carriage return in your text. Line 1 is the code for a carriage return in C# and line 3 shows an example of how to use it.
0 818 posted 15 years ago by mordecaix7
This is stupidly simple, but I always forget it.
1 919 posted 15 years ago by rengber
0 965 posted 15 years ago by vcskicks
Will return a string that has any matched URLs wrapped in `<a>` tags. Example: `"This is a link to http://foobar.com . Please visit !"` Becomes: `"This is a link to <a href='http://foobar.com'>http://foobar.com</a> . Please visit!"` Note: Op...
2 4619 posted 15 years ago by jasonseney
Example uses an object from 3rd party API. Needed to turn it into xml for returning from a webservice.
0 716 posted 15 years ago by jasonseney