Monday, April 13, 2009

What is in a page

Page Object contains a reference to:
• Request object
• Response object

• Application object
• Session object

• Trace object
• Server object
• User Object
• PreviousPage object

ASP.NET Event Load Sequences

Pre-init event
• Ispostback is available but not control view states
• Set Global properties
o Dynamic master page
o Profile properties
o Applied skin/theme settings
• Recreate dynamically created controls

Init Event
• Fires after elements been initialized and skin setting has been applied
• Read or write any specific control properties

Init Complete
• After all initialization been complete
• Implement logic that depends on controls be initialized

Preload
• Process control before they are loaded
• A pre-load for each control
• After this viewstate gets initializes and postback information gets initialized

Load event
• Page load then each control’s load and then any specific control events (change,click etc)

Load complete
• Control all loaded, viewstates been loaded and validated has occured

Prerender
• All databind been called
• All child prerender been called

Save View State
• All values has been created and saved
• Can’t implement logic that we want to appeared they will be ignored
• Can implement logic that used the viewstate

Thursday, April 09, 2009

Retriving application path

Virtual path or web path

dim webPath as string = HttpContext.Current.Request.ApplicationPath

works the same as "~"


Physical is the actual path
dim physicalPath as string = HttpContext.Current.Request.MapPath(appPath)

Thursday, March 05, 2009

Gridview.Databind - Once per load

* Remove extra databinds for grideviews - You should only have one per page load.

I was getting "Item has already been added" error in a page containing multiple multiviews/views/gridviews. This makes it very easy to mistakenly add an extra databind somewhere.

This problem is also exasperated by the usage of different select sqls populating the gridviews.

Inaddition for some reason the extra databind does not cause a problem in my local machine or my company server. It only started acting up when I uploaded to a ISP.

Thursday, February 26, 2009

IE8

I upgraded to IE8 recently and it seem to be much smarter. However it does not display my websites the same way.

From what I have seeem it tends to disply more along the line of firefox as oppose to IE7

Some browser differences for validation controls

For IE when i disable a control it takes the validation control out of play, but when I run the same file in songbird it does not work. It is not visible but it interferes with the submitting of the form.

When I set the visible property of the validation control to disable then it works.

Tuesday, February 17, 2009

How to Fing Control in EmptyData Row in Gridview for VB.NET

It's simple but not very intuiative.

VB.NET
gvDisplay.Controls(0).Controls(0).Controls(0).FindControl("controlid")

Friday, February 13, 2009

VB.NET turn links cursor into text cursor

Sometimes vb.net application will turn the curesor for links (pointer) into text cursor (I).

I find that if you specifically specify the a tag to a pointer then it will fix that problem.

a
{
cursor:pointer;
}

.NET Request object properties

Request Property Function and Example
  • ApplicationPath -Returns the a Web server relative path to your application root /WestwindWebStore/

  • PhysicalApplicationPath -
    Returns a local file system path to your application root D:\inetpub\wwwroot\WestWindWebStore\

  • PhysicalPath - Returns the full file system path to the currently executing script D:\inetpub\wwwroot\WestWindWebStore\Item.aspx

  • CurrentExecutionFilePath - FilePath

  • Path - In most situations all of these return the virtual path to the currently executing script relative to the Web Server root. /WestwindWebStore/item.aspx

  • PathInfo - Returns any extra path following the script name. Rarely used – this value is usually blank. /WestwindWebStore/item.aspx/ExtraPathInfo

  • RawUrl - Returns the application relative URL including querystring or pathinfo
    /WestwindWebStore/item.aspx?sku=WWHELP30

  • Url - Returns the fully qualified URL including domain and protocol
    http://www.west-wind.com/Webstore/item.aspx?sku=WWHELP30

  • Page.TemplateSourceDirectory - Control.TemplateSourceDirectory
    Returns the virtual path of the currently executing control (or page). Very useful if you need to know the location of your ASCX control instead of the location of the page. /WestwindWebStore/admin


Above copied from http://www.west-wind.com/weblog/posts/269.aspx

Link to the application root
use Request.ApplicationPath

Thursday, February 12, 2009

Set Focus to textbox after updatepanel updates

VB.NET

I have a gridview in a update panel displaying a set of records. When I select a record I want to set focus to a text box. This following script will do that

Set the following cod under the script manager or you will get the sys object not found error

<script type="text/javascript" language="javascript">
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function EndRequestHandler(sender, args) {
//Use timer so that the script will wait .5 sec before it fires to let page complete rendering the txtDSChartNumber element
setTimeout ( 'setFocus(\'txtDSChartNumber\')', 500 );
}
function setFocus(controlid) {
if (document.getElementById(controlid)){
document.getElementById(controlid).focus();
document.getElementById(controlid).select();
}
}
</script>