Can someone help me stop repeating code?

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?
 
S

Showjumper

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.
 
V

Vince

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.
 
V

Vince

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?
 
J

Juan T. Llibre

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 )
 
L

Larry Bud

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?
 
G

Ghostman

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?
 
T

ThunderMusic

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
 
T

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top