lordfa9 Posted August 7, 2006 Share Posted August 7, 2006 I have this code to check if a variable has been entered into the querystring and to display an error message if there isn't any if request.querystring("tblname")<>"" then tblname=request.querystring("tblname")else Response.Write "Error!!!" Response.End end if the remainder of my code contains html elements that i don't want displayed if the error conditions is triggered, is there any way i can just cause the "Error!!!" message to diaplay only? Link to comment Share on other sites More sharing options...
justsomeguy Posted August 7, 2006 Share Posted August 7, 2006 Response.End should be doing that, is it not working? Maybe put parens on the end of itResponse.End() Link to comment Share on other sites More sharing options...
lordfa9 Posted August 8, 2006 Author Share Posted August 8, 2006 did just that, still dosn't work Link to comment Share on other sites More sharing options...
justsomeguy Posted August 8, 2006 Share Posted August 8, 2006 You mean it writes out the "Error!!!", and then continues executing whatever is below the IF statement? Link to comment Share on other sites More sharing options...
lordfa9 Posted August 8, 2006 Author Share Posted August 8, 2006 You mean it writes out the "Error!!!", and then continues executing whatever is below the IF statement?yup, all the remaining html codes below the "end if" statement Link to comment Share on other sites More sharing options...
justsomeguy Posted August 8, 2006 Share Posted August 8, 2006 Do you have buffering on? I don't think that would make a difference, but I guess it might. Response.End has always stopped execution for me though, I'm not sure what else to say. If it writes out the error message, and you know that Response.end is actually being executed and not working, then I don't know what the problem could be. All I can think of is that it is not getting executed. What if you put another Response.End after the end if statement? Link to comment Share on other sites More sharing options...
lordfa9 Posted August 10, 2006 Author Share Posted August 10, 2006 if you meant changing the code to if request.querystring("tblname")<>"" then tblname=request.querystring("tblname")else Response.Write "Error!!!" Response.End() end ifResponse.End() now it stops everything from being shown, whether the error statement has been triggered or notOn a related note, does Response.End affect only asp codes or both asp & html codes? Link to comment Share on other sites More sharing options...
justsomeguy Posted August 10, 2006 Share Posted August 10, 2006 Response.End ends the response. The response is what the web server sends to the browser. So when you invoke response.end, the response that goes to the browser stops at that point. Or, if buffering is on, the building of the response ends and the response gets sent at that point.It would probably be helpful if you posted all of your code, or at least the 10-20 lines both before and after the IF statement. Link to comment Share on other sites More sharing options...
lordfa9 Posted August 10, 2006 Author Share Posted August 10, 2006 here it is <html><style type="text/css"><!--#Layer1 { position:absolute; width:172px; height:21px; z-index:1; left: 12px; top: 51px;}--></style><body><h1 align="center">Class <%=Request.Querystring("tblname")%></h1><div id="Layer1"><a href="/subjects.asp" target="_blank">What Do These Mean?</a></div><table border="1" width="100%" bgcolor="#fff5ee"><tr><th align="left" width=20% bgcolor="#b0c4de"><a href="displayhw.asp?tblname=<%=Request.Querystring("tblname")%>&sort=SubCode&ordering=ASC">Subject Code</a></th><th align="left" width=12% bgcolor="#b0c4de"><a href="displayhw.asp?tblname=<%=Request.Querystring("tblname")%>&sort=DateGiven&ordering=DESC">Date Given</a></th><th align="left" width=12% bgcolor="#b0c4de"><a href="displayhw.asp?tblname=<%=Request.Querystring("tblname")%>&sort=DateDue&ordering=DESC">Date Due</a></th><th align="left" bgcolor="#b0c4de">Information</th></tr><%if request.querystring("tblname")<>"" then tblname=request.querystring("tblname")else Response.Write "<h1>Error!!! Please choose a class first</h1>" Response.End()end ifif request.querystring("sort")<>"" then sort=request.querystring("sort")else sort="DateGiven"end ifif request.querystring("ordering")<>"" then ordering=request.querystring("ordering")else ordering="DESC"end ifset conn=Server.CreateObject("ADODB.Connection")conn.Provider="Microsoft.Jet.OLEDB.4.0"conn.Open(Server.Mappath("/database.mdb"))set rs=Server.CreateObject("ADODB.recordset")sql="SELECT Subcode, DateGiven, DateDue, Information FROM " & tblname & " Order BY " & sort & " " & ordering & ""rs.Open sql,conndo until rs.EOF response.write("<tr>") for each x in rs.Fields response.write("<td>" & x.value & "</td>") next rs.MoveNext response.write("</tr>")looprs.closeconn.close%></table></body></html> so what i get if the error msg is triggered is (manually triggered error condition and went to view->source) <html><style type="text/css"><!--#Layer1 { position:absolute; width:172px; height:21px; z-index:1; left: 12px; top: 51px;}--></style><body><h1 align="center">Class </h1><div id="Layer1"><a href="/subjects.asp" target="_blank">What Do These Mean?</a></div><table border="1" width="100%" bgcolor="#fff5ee"><tr><th align="left" width=20% bgcolor="#b0c4de"><a href="displayhw.asp?tblname=&sort=SubCode&ordering=ASC">Subject Code</a></th><th align="left" width=12% bgcolor="#b0c4de"><a href="displayhw.asp?tblname=&sort=DateGiven&ordering=DESC">Date Given</a></th><th align="left" width=12% bgcolor="#b0c4de"><a href="displayhw.asp?tblname=&sort=DateDue&ordering=DESC">Date Due</a></th><th align="left" bgcolor="#b0c4de">Information</th></tr><h1>Error!!! Please choose a class first</h1> despite what the html says, the error msg appears above the table, dunno y source is like this,on hindsight could it have something to do with the positioning (from top to down) of the error segment of my code? Link to comment Share on other sites More sharing options...
justsomeguy Posted August 10, 2006 Share Posted August 10, 2006 Oooooh, ok. It's an HTML issue then. The HTML is invalid. The error message is not actually in the table, and most browsers will display that type of thing above the table. You probably want to do this:Response.Write "<tr><td colspan='3'><h1>Error!!! Please choose a class first</h1></td></tr></table></body></html>"That will put the message inside the table structure, and then close the rest of the page before it quits.Also, put the style tag in a <head> section. <html> <head> <title>page title</title> <style>... </style> </head> <body>... Link to comment Share on other sites More sharing options...
lordfa9 Posted August 11, 2006 Author Share Posted August 11, 2006 hmm i seemed to have solved the prob all i did was to shift the if request.querystring("tblname")<>"" then tblname=request.querystring("tblname")else Response.Write "<tr><td colspan='4'><h1>Error!!! Please choose a class first</h1></td></tr>" Response.End()end if code to the top (directly after the <% tag) Now if the error msg is triggered a 1 col 1 row table with the error message in it will appear Link to comment Share on other sites More sharing options...
justsomeguy Posted August 11, 2006 Share Posted August 11, 2006 Right. View the HTML source and make sure that you are ending the page correctly, with </body> and </html>. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now