locked
Page_Load event RRS feed

  • Question

  • User-505780509 posted
    If you are like me, you probably find it a pain in C#'s partial classes that you gotta manually type the private void Page_Load(object source, EventArgs e){ } stub. Anyways, not like this is magic, but if you aren't familiar with expansions, goto: C:\Program Files\Microsoft Visual Studio 8\VC#\Expansions\1033\Expansions Create a file called "PageLoad.xml" and put this in it: <?xml version="1.0" encoding="utf-8" ?> <CodeSnippet Format="1.0.0"> <Header> <Title>Page Load method stub</Title> <Shortcut>OnLoad</Shortcut> <!-- alternate name you might like: <Shortcut>fori</Shortcut> --> <Description>Page Load Method Stub</Description> <SnippetTypes> <SnippetType>Expansion</SnippetType> <SnippetType>SurroundsWith</SnippetType> </SnippetTypes> </Header> <Snippet> <![CDATA[private void Page_Load(object source, EventArgs e){ $selected$ $end$ }]]> </Snippet> </CodeSnippet> You can now simply type OnLoad<TAB> and the stub will be written. If anyone know how to use the supposedly existing <Imports> section of expansions, plz let me know.
    Thursday, August 19, 2004 7:37 PM

All replies

  • User1932872737 posted
    Thanks this is a nice trick. I do not understand either why the IDE support for adding events in VB is easier than in C#. But I found that in the December CTP version the folder is now: C:\<....wherever...>\Microsoft Visual Studio 8\VC#\Snippets\1033\Snippets And I had to change the XML file a little bit to: <?xml version="1.0" encoding="utf-8" ?> <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"> <CodeSnippet Format="1.0.0"> <Header> <Title>Page Load method stub</Title> <Shortcut>PageLoad</Shortcut> <!-- alternate name you might like: <Shortcut>fori</Shortcut> --> <Description>Page Load Method Stub</Description> <SnippetTypes> <SnippetType>Expansion</SnippetType> <SnippetType>SurroundsWith</SnippetType> </SnippetTypes> </Header> <Snippet> <![CDATA[private void Page_Load(object source, EventArgs e) { $selected$ $end$ }]]> </Snippet> </CodeSnippet> </CodeSnippets>
    Saturday, December 25, 2004 12:09 PM
  • User320447433 posted
    In visual studio, wouldn't double clicking on the web form in design view add this? Not using asp.net 2.0 yet but I'm pretty sure I saw this somewhere.
    Thursday, March 10, 2005 2:37 PM
  • User961349301 posted
    thelomex: Yes that is true.
    Thursday, March 10, 2005 2:44 PM
  • User-129819914 posted

    Shouldn't there be a WebForm or Asp.net  snippets group? There is one for WinForms etc.
    Beyond  Page_Load there are other missing snippets such as the other events Page_Init etc.

    Monday, October 24, 2005 1:55 PM
  • User-1563960693 posted
    you already have an expansion for Page_Load...

    override <SPACE> onload

    but....this is my preference,  [;)]

    Jason
    Thursday, October 27, 2005 11:04 AM