Can someone help me stop repeating code?

  • Thread starter Thread starter Vince
  • Start date Start date
V

Vince

I have this code that appears at the top of every page

I have tried putting this into my master page, however, the error
message doesnt appear when I do this even though I have the variables
declared in the other pages.

<asp:Content id="contentErrors" ContentPlaceHolderID="siteErrors"
runat="server">
<% if (pageErrors) { %>
<div class="siteError">
<h2>Error</h2><em><%=pageError %></em>
</div>
<% } %>
</asp:Content>

I could use an iframe and link a error.aspx page within it and pass
the values as parameters via the URL, but this seems cumbersome to me.

Any suggestions?
 
You can set a custom error page in web.config. Is that what you need? Also
you can use Server.GetLastError to get the error message.
 
You can set a custom error page in web.config. Is that what you need? Also

Well thats a whole error page, im just looking at a div that appears
at the top of every page and is only displayed when needed.

Ill have a look at GetLastError. Cheers.
 
Well thats a whole error page, im just looking at a div that appears
at the top of every page and is only displayed when needed.

Ill have a look at GetLastError. Cheers.

Actually I checkd GetLastError. This seems more to do with application
level errors. Im after something for user errors such as missing data
entry or wrong formatted date.

Anyone?
 
re:
!> Im after something for user errors such as missing data entry or wrong formatted date.

For that, use structured error exception handling.

( Try, Catch, Finally )




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
 
I have this code that appears at the top of every page

I have tried putting this into my master page, however, the error
message doesnt appear when I do this even though I have the variables
declared in the other pages.

<asp:Content id="contentErrors" ContentPlaceHolderID="siteErrors"
runat="server">
<% if (pageErrors) { %>
<div class="siteError">
<h2>Error</h2><em><%=pageError %></em>
</div>
<% } %>
</asp:Content>

I could use an iframe and link a error.aspx page within it and pass
the values as parameters via the URL, but this seems cumbersome to me.

Any suggestions?

What about in a user control?
 
Sorry for the Hijack..


speaking of Error Handling. I have set it up at the Application level
a few times using global.asax, but is there a way to set up a default
global.asax file that i can have multiple asp.net applications point
to?
 
Hi,
I think it's a "BasePage" case... If you make all your pages inherit from a
"BasePage" class (that inherits from Page), you can put everything you want
"global" in this "BasePage" without needing every single page to declare for
example the 'pageErrors' variable.

I hope it helps

ThunderMusic
 
hi
btw, I also agree with Larry Bud's post saying you could use a user control,
but you would still need to copy-paste the usercontrol to every single
page... coupled with the "BasePage", it could be terrific... ;)

I hope it helps

ThunderMusic
 
Back
Top