Monday, March 30, 2009

Autowidening DropDownList (IE only!)

<asp:DropDownList ID="ddl" runat="server" Width="100px" onmouseover="this.style.width = 'auto';" onfocus="this.hasFocus = true;" onblur="this.style.width = 100; this.hasFocus = false;" onmouseout="if (!this.hasFocus) this.style.width = 100;" />

Works in Internet Explorer only - in Firefox the control does not narrow back.

Saturday, January 31, 2009

Send file to browser

private void SendFile(string fileText, string fileName, string contentType) {
  this.Response.Clear();
  this.Response.AddHeader("content-disposition", "attachment;filename=" + fileName);
  this.Response.ContentType = contentType;
  this.Response.Write(fileText);
  this.Response.End();
}
Typical content types: Text "text/plain" PDF "application/pdf" Got it from: http://coercedcode.blogspot.com/2007/08/sending-files-and-file-contents-to.html. Starting the download with a button inside an UpdatePanel? Register the button for a regular, not partial postback:
ScriptManager.GetCurrent(this.Page).RegisterPostBackControl(exportButton);

Tuesday, January 27, 2009

Page transfer effect that works in Internet Explorer (blendTrans effect)

I can never remember this.
<meta http-equiv="Page-Enter" content="blendTrans(Duration=0.0)">

Monday, January 19, 2009

Quickly check web page performance

Paste this somewhere in your codebehind, putting the dt definitions around the suspected code:
DateTime dt = DateTime.Now;
DateTime dt2 = DateTime.Now; 
DateTime dt3 = DateTime.Now; 
this.debugLiteral.Text = string.Format("<div>|{0}||{1}||{2}|</div>", dt, dt2, dt3);
And paste this somewhere in your aspx:
<asp:Literal ID="debugLiteral" runat="server" />

Monday, December 15, 2008

Google hosted jQuery

Link to jQuery library hosted on Google's CDN:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
http://encosia.com/2008/12/10/3-reasons-why-you-should-let-google-host-jquery-for-you/

Wednesday, December 10, 2008

string.Empty and string.Format code snippets

Just put them in files "string.Empty.snippet" and "string.Format.snippet" in folder "My Documents\Visual Studio 2008\Code Snippets\Visual C#\My Code Snippets". More on creating code snippets: http://msdn.microsoft.com/en-us/library/ms165393(VS.80).aspx. string.Empty:
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
   <Header>
       <Title>se</Title>
       <Shortcut>se</Shortcut>
       <Description>Code snippet for "string.Empty"</Description>
       <SnippetTypes>
           <SnippetType>Expansion</SnippetType>
       </SnippetTypes>
   </Header>
   <Snippet>
       <Code Language="csharp">
           <![CDATA[string.Empty$end$]]>
       </Code>
   </Snippet>
</CodeSnippet>
</CodeSnippets>
string.Format():
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
   <Header>
       <Title>sf</Title>
       <Shortcut>sf</Shortcut>
       <Description>Code snippet for "string.Format()"</Description>
       <SnippetTypes>
           <SnippetType>Expansion</SnippetType>
           <SnippetType>SurroundsWith</SnippetType>
       </SnippetTypes>
   </Header>
   <Snippet>
       <Code Language="csharp">
           <![CDATA[string.Format($selected$$end$)]]>
       </Code>
   </Snippet>
</CodeSnippet>
</CodeSnippets>