Showing posts with label thefollowing. Show all posts
Showing posts with label thefollowing. Show all posts

Thursday, March 29, 2012

Server side viewstate

In looking for a way to trim down viewstate, I came across the
following articles to store viewstate in session:

http://aspalliance.com/72
http://msdn.microsoft.com/library/d...ml/PgStPrst.asp
It appears as if the first link is actually better as it allows for a
"history" of viewstates to be availabale.

Anyone have experience using either one of these methods?

Thanks."emde" <emdeusenet@.yahoo.comwrote in message
news:1161638474.044477.141050@.b28g2000cwb.googlegr oups.com...

Quote:

Originally Posted by

In looking for a way to trim down viewstate, I came across the
following articles to store viewstate in session:
>
http://aspalliance.com/72
>
http://msdn.microsoft.com/library/d...ml/PgStPrst.asp
>
>
It appears as if the first link is actually better as it allows for a
"history" of viewstates to be availabale.
>
Anyone have experience using either one of these methods?


ViewState, as with hundreds of other features of ASP.NET, is extremely
useful when it's extremely useful.

But let's not get too carried away here - ViewState *does* add a bit of
overhead to every page which uses it, but unless the page is huge with loads
and loads of WebControls and HTMLControls, it's probably not going to make
that much of a difference to most users. It's just text after all. The page
may take a second or so longer to load, but that's about it...

If the page is huge with loads and loads of WebControls and HTMLControls,
then it's been badly designed in the first place, so ViewState really is the
least of your worries...:-)

There are loads and loads of ways to improve the performance of ASP.NET
sites, but ViewState is IMO opinion fairly far down the list.

By all means be aware that it's always a "good thing" to minimise the amount
of traffic between server and client and back again, so set
EnableViewState="false" for all those controls which don't need it - but
it's really not necessary to devote any more time to it than that...
Mark Rae wrote:

Quote:

Originally Posted by

There are loads and loads of ways to improve the performance of ASP.NET
sites, but ViewState is IMO opinion fairly far down the list.
>...
By all means be aware that it's always a "good thing" to minimise the amount
of traffic between server and client and back again, so set
EnableViewState="false" for all those controls which don't need it - but
it's really not necessary to devote any more time to it than that...


While I agree with you, I am working with the wizard control and
viewstate gets out of hand really quick :)
"emde" <emdeusenet@.yahoo.comwrote in message
news:1161639998.986367.317610@.e3g2000cwe.googlegro ups.com...

Quote:

Originally Posted by

Mark Rae wrote:
>

Quote:

Originally Posted by

>There are loads and loads of ways to improve the performance of ASP.NET
>sites, but ViewState is IMO opinion fairly far down the list.
>>...
>By all means be aware that it's always a "good thing" to minimise the
>amount
>of traffic between server and client and back again, so set
>EnableViewState="false" for all those controls which don't need it - but
>it's really not necessary to devote any more time to it than that...


>
>
While I agree with you, I am working with the wizard control and
viewstate gets out of hand really quick :)


Hmm - it shouldn't if you're careful... You really only need to enable
ViewState on the controls within the individual panels...

That said, I really don't like the Wizard control / <asp:MultiViewcontrol
for just this reason...

It also makes client-side validation almost impossible because only the
controls in the current panel are actually streamed down to the client...

I really wish Microsoft had come up with something along the lines of the
old IE:WebControls for this in ASP.NET 2...I realise that they were for IE
only but, in an enclosed corporate intranet where all client machines are
running IE, the IE:WebControls were truly superb...

Monday, March 26, 2012

Server side viewstate

In looking for a way to trim down viewstate, I came across the
following articles to store viewstate in session:
http://aspalliance.com/72
http://msdn.microsoft.com/library/d...
rst.asp
It appears as if the first link is actually better as it allows for a
"history" of viewstates to be availabale.
Anyone have experience using either one of these methods?
Thanks."emde" <emdeusenet@.yahoo.com> wrote in message
news:1161638474.044477.141050@.b28g2000cwb.googlegroups.com...

> In looking for a way to trim down viewstate, I came across the
> following articles to store viewstate in session:
> http://aspalliance.com/72
> http://msdn.microsoft.com/library/d...r />
tPrst.asp
>
> It appears as if the first link is actually better as it allows for a
> "history" of viewstates to be availabale.
> Anyone have experience using either one of these methods?
ViewState, as with hundreds of other features of ASP.NET, is extremely
useful when it's extremely useful.
But let's not get too carried away here - ViewState *does* add a bit of
overhead to every page which uses it, but unless the page is huge with loads
and loads of WebControls and HTMLControls, it's probably not going to make
that much of a difference to most users. It's just text after all. The page
may take a second or so longer to load, but that's about it...
If the page is huge with loads and loads of WebControls and HTMLControls,
then it's been badly designed in the first place, so ViewState really is the
least of your worries...:-)
There are loads and loads of ways to improve the performance of ASP.NET
sites, but ViewState is IMO opinion fairly far down the list.
By all means be aware that it's always a "good thing" to minimise the amount
of traffic between server and client and back again, so set
EnableViewState="false" for all those controls which don't need it - but
it's really not necessary to devote any more time to it than that...
Mark Rae wrote:

> There are loads and loads of ways to improve the performance of ASP.NET
> sites, but ViewState is IMO opinion fairly far down the list.
>...
> By all means be aware that it's always a "good thing" to minimise the amou
nt
> of traffic between server and client and back again, so set
> EnableViewState="false" for all those controls which don't need it - but
> it's really not necessary to devote any more time to it than that...
While I agree with you, I am working with the wizard control and
viewstate gets out of hand really quick :)
"emde" <emdeusenet@.yahoo.com> wrote in message
news:1161639998.986367.317610@.e3g2000cwe.googlegroups.com...

> Mark Rae wrote:
>
>
> While I agree with you, I am working with the wizard control and
> viewstate gets out of hand really quick :)
Hmm - it shouldn't if you're careful... You really only need to enable
ViewState on the controls within the individual panels...
That said, I really don't like the Wizard control / <asp:MultiView> control
for just this reason...
It also makes client-side validation almost impossible because only the
controls in the current panel are actually streamed down to the client...
I really wish Microsoft had come up with something along the lines of the
old IE:WebControls for this in ASP.NET 2...I realise that they were for IE
only but, in an enclosed corporate intranet where all client machines are
running IE, the IE:WebControls were truly superb...

Thursday, March 22, 2012

Server.GetLastError

Hello,
I am trying to get the last occured error via the
following code:
Sub Page_Load(...)
Dim zero As Integer = 0
Try
Dim err As Integer = 10 / zero
Catch ex As Exception
End Try
Response.write(Server.GetLastError.Message)
End Sub
However the above code always throws an error at the
response.write line with:
Object reference not set to an instance of an object.
Anybody knows why this is happening?Well, first off 10/0 will not throw an error. I also assume you must have
Option Strict Off or your code would not even compile: err would need to be
dimmed as a double or you would need ctype(10/zero, double) for code to
compile.
I think GetLastError only returns the last unhandled error, during the
current context, and I think the page's Page_Error event or global.asax
Application_Error event has to be raised to access it. Once one of those
events is raised Server.GetLastError is available anywhere in your
code...for the remainder of the current context / request
Example:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim zero As Integer = 0
Dim err As Double = 10 / CType("x", Integer)
End Sub
Private Sub Page_Error(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Error
Response.Write(Server.GetLastError.Message)
End Sub
Or since it's now available anywhere, you could also do something like this:
Private Sub Page_Error(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Error
Server.Transfer("error.aspx")
End Sub
And then in error.aspx
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Response.Write(Server.GetLastError.Message)
End Sub
"VK" <anonymous@.discussions.microsoft.com> wrote in message
news:0dfb01c54132$353bf820$a401280a@.phx.gbl...
> Hello,
> I am trying to get the last occured error via the
> following code:
> Sub Page_Load(...)
> Dim zero As Integer = 0
> Try
> Dim err As Integer = 10 / zero
> Catch ex As Exception
> End Try
> Response.write(Server.GetLastError.Message)
> End Sub
> However the above code always throws an error at the
> response.write line with:
> Object reference not set to an instance of an object.
> Anybody knows why this is happening?
Since you are catching the exception, it is no longer an error.
bill
"VK" <anonymous@.discussions.microsoft.com> wrote in message
news:0dfb01c54132$353bf820$a401280a@.phx.gbl...
> Hello,
> I am trying to get the last occured error via the
> following code:
> Sub Page_Load(...)
> Dim zero As Integer = 0
> Try
> Dim err As Integer = 10 / zero
> Catch ex As Exception
> End Try
> Response.write(Server.GetLastError.Message)
> End Sub
> However the above code always throws an error at the
> response.write line with:
> Object reference not set to an instance of an object.
> Anybody knows why this is happening?
Hello VK,
If this code would generate an error (which it wont as detailed by Brad),
you're swallowing it anyways. You need to remove the try/catch.
Matt Berther
http://www.mattberther.com

> Hello,
> I am trying to get the last occured error via the following code:
> Sub Page_Load(...)
> Dim zero As Integer = 0
> Try
> Dim err As Integer = 10 / zero
> Catch ex As Exception
> End Try
> Response.write(Server.GetLastError.Message)
> End Sub
> However the above code always throws an error at the response.write
> line with:
> Object reference not set to an instance of an object.
> Anybody knows why this is happening?
>

Server.GetLastError

Hello,

I am trying to get the last occured error via the
following code:

Sub Page_Load(...)
Dim zero As Integer = 0
Try
Dim err As Integer = 10 / zero
Catch ex As Exception
End Try

Response.write(Server.GetLastError.Message)
End Sub

However the above code always throws an error at the
response.write line with:

Object reference not set to an instance of an object.

Anybody knows why this is happening?Well, first off 10/0 will not throw an error. I also assume you must have
Option Strict Off or your code would not even compile: err would need to be
dimmed as a double or you would need ctype(10/zero, double) for code to
compile.

I think GetLastError only returns the last unhandled error, during the
current context, and I think the page's Page_Error event or global.asax
Application_Error event has to be raised to access it. Once one of those
events is raised Server.GetLastError is available anywhere in your
code...for the remainder of the current context / request

Example:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim zero As Integer = 0
Dim err As Double = 10 / CType("x", Integer)
End Sub

Private Sub Page_Error(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Error
Response.Write(Server.GetLastError.Message)
End Sub

Or since it's now available anywhere, you could also do something like this:

Private Sub Page_Error(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Error
Server.Transfer("error.aspx")
End Sub

And then in error.aspx

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Response.Write(Server.GetLastError.Message)
End Sub

"VK" <anonymous@.discussions.microsoft.com> wrote in message
news:0dfb01c54132$353bf820$a401280a@.phx.gbl...
> Hello,
> I am trying to get the last occured error via the
> following code:
> Sub Page_Load(...)
> Dim zero As Integer = 0
> Try
> Dim err As Integer = 10 / zero
> Catch ex As Exception
> End Try
> Response.write(Server.GetLastError.Message)
> End Sub
> However the above code always throws an error at the
> response.write line with:
> Object reference not set to an instance of an object.
> Anybody knows why this is happening?
Well, first off 10/0 will not throw an error. I also assume you must have
Option Strict Off or your code would not even compile: err would need to be
dimmed as a double or you would need ctype(10/zero, double) for code to
compile.

I think GetLastError only returns the last unhandled error, during the
current context, and I think the page's Page_Error event or global.asax
Application_Error event has to be raised to access it. Once one of those
events is raised Server.GetLastError is available anywhere in your
code...for the remainder of the current context / request

Example:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim zero As Integer = 0
Dim err As Double = 10 / CType("x", Integer)
End Sub

Private Sub Page_Error(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Error
Response.Write(Server.GetLastError.Message)
End Sub

Or since it's now available anywhere, you could also do something like this:

Private Sub Page_Error(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Error
Server.Transfer("error.aspx")
End Sub

And then in error.aspx

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Response.Write(Server.GetLastError.Message)
End Sub

"VK" <anonymous@.discussions.microsoft.com> wrote in message
news:0dfb01c54132$353bf820$a401280a@.phx.gbl...
> Hello,
> I am trying to get the last occured error via the
> following code:
> Sub Page_Load(...)
> Dim zero As Integer = 0
> Try
> Dim err As Integer = 10 / zero
> Catch ex As Exception
> End Try
> Response.write(Server.GetLastError.Message)
> End Sub
> However the above code always throws an error at the
> response.write line with:
> Object reference not set to an instance of an object.
> Anybody knows why this is happening?
Since you are catching the exception, it is no longer an error.

bill

"VK" <anonymous@.discussions.microsoft.com> wrote in message
news:0dfb01c54132$353bf820$a401280a@.phx.gbl...
> Hello,
> I am trying to get the last occured error via the
> following code:
> Sub Page_Load(...)
> Dim zero As Integer = 0
> Try
> Dim err As Integer = 10 / zero
> Catch ex As Exception
> End Try
> Response.write(Server.GetLastError.Message)
> End Sub
> However the above code always throws an error at the
> response.write line with:
> Object reference not set to an instance of an object.
> Anybody knows why this is happening?
Hello VK,

If this code would generate an error (which it wont as detailed by Brad),
you're swallowing it anyways. You need to remove the try/catch.

--
Matt Berther
http://www.mattberther.com

> Hello,
> I am trying to get the last occured error via the following code:
> Sub Page_Load(...)
> Dim zero As Integer = 0
> Try
> Dim err As Integer = 10 / zero
> Catch ex As Exception
> End Try
> Response.write(Server.GetLastError.Message)
> End Sub
> However the above code always throws an error at the response.write
> line with:
> Object reference not set to an instance of an object.
> Anybody knows why this is happening?