Redirect not working inside subroutine

M

mister-Ed

I need to look into a database table (cats) to see if a certain
category and its resulting resultset should be shown to users if it is
deemed "universal" , or the column 'ur' is tagged with the indicator
'univ' ( this is just a character datatype, but later will be changed
to a boolean true or false "bit" datatype because right now i'm just
working with one sole region) . But when i run the following sub and
subsequent block to check for "univ" , I don't get my script to
redirect to the page I indicate, it doesn't want to do a
response.redirect inside this block (???)



''''''''''''

<script runat="server">

Protected ur As string

Protected scate As string

Protected ssubcat as string
Protected scounty as string
Protected stown as string


'Handle page load event
Sub Page_Load(Sender As Object, E As EventArgs)

dim szone as string

scounty = request.querystring("county")
stown = request.querystring("town")
szone = request.querystring("bigzone")
scate = request.querystring("category")
ssubcat = request.querystring("subcat")

dim sqlcatchekstr as string


Dim MyConnection As SQLConnection
''Dim MyCommand As SQLDataAdapter
dim MyDataset As DataSet
dim MyTable As DataTable

sqlcatchekstr = "select category,subcategory,uregion from cats
where category ='" + scate + "'"

MyConnection = New SqlConnection("Data
Source=myserver.net;Initial Catalog=mydb;User Id=myid;Password=pwd;")
' Create a Command object with the SQL statement.
Dim Mycommand As New SqlCommand(sqlcatchekstr, Myconnection)


Myconnection.Open()
'init the reader
dim reader As SqlDataReader = MyCommand.ExecuteReader()

' Call Read before accessing data.
do While reader.Read()

ur = reader("uregion").ToString()


loop
reader.Close()

if ur = "univ" then
response.redirect("cat-universal.aspx?category=" & scate &
"&subcat=" & ssubcat & "&county=" & scounty & "")

end if

MyConnection.Close

End Sub

</script>



''''''''''''''''

thanks

ED
 
N

Newbie Coder

Ed,

Ask your question in the ASP.NET newsgroup:

microsoft.public.dotnet.framework.aspnet
 
R

rowe_newsgroups

I need to look into a database table (cats) to see if a certain
category and its resulting resultset should be shown to users if it is
deemed "universal" , or the column 'ur' is tagged with the indicator
'univ' ( this is just a character datatype, but later will be changed
to a boolean true or false "bit" datatype because right now i'm just
working with one sole region) . But when i run the following sub and
subsequent block to check for "univ" , I don't get my script to
redirect to the page I indicate, it doesn't want to do a
response.redirect inside this block (???)

''''''''''''

<script runat="server">

Protected ur As string

Protected scate As string

Protected ssubcat as string
Protected scounty as string
Protected stown as string

'Handle page load event
Sub Page_Load(Sender As Object, E As EventArgs)

dim szone as string

scounty = request.querystring("county")
stown = request.querystring("town")
szone = request.querystring("bigzone")
scate = request.querystring("category")
ssubcat = request.querystring("subcat")

dim sqlcatchekstr as string

Dim MyConnection As SQLConnection
''Dim MyCommand As SQLDataAdapter
dim MyDataset As DataSet
dim MyTable As DataTable

sqlcatchekstr = "select category,subcategory,uregion from cats
where category ='" + scate + "'"

MyConnection = New SqlConnection("Data
Source=myserver.net;Initial Catalog=mydb;User Id=myid;Password=pwd;")
' Create a Command object with the SQL statement.
Dim Mycommand As New SqlCommand(sqlcatchekstr, Myconnection)

Myconnection.Open()
'init the reader
dim reader As SqlDataReader = MyCommand.ExecuteReader()

' Call Read before accessing data.
do While reader.Read()

ur = reader("uregion").ToString()

loop
reader.Close()

if ur = "univ" then
response.redirect("cat-universal.aspx?category=" & scate &
"&subcat=" & ssubcat & "&county=" & scounty & "")

end if

MyConnection.Close

End Sub

</script>

''''''''''''''''

thanks

ED

I'm curious - will it do a Server.Transfer to the new page?

Thanks,

Seth Rowe
 
R

rowe_newsgroups

I'm curious - will it do a Server.Transfer to the new page?

Thanks,

Seth Rowe

I forgot this in my last post:

Try using the overload for Response.Redirect that tells the method to
stop processing the current page. I have a feeling your response is
being overwritten by code that runs after yours.

i.e. Change:

response.redirect("cat-universal.aspx?category=" & scate &
"&subcat=" & ssubcat & "&county=" & scounty & "")

to

response.redirect("cat-universal.aspx?category=" & scate &
"&subcat=" & ssubcat & "&county=" & scounty & "", True)


Thanks,

Seth Rowe
 
M

mister-Ed

I forgot this in my last post:

Try using the overload for Response.Redirect that tells the method to
stop processing the current page. I have a feeling your response is
being overwritten by code that runs after yours.

i.e. Change:

response.redirect("cat-universal.aspx?category=" & scate &
"&subcat=" & ssubcat & "&county=" & scounty & "")

to

response.redirect("cat-universal.aspx?category=" & scate &
"&subcat=" & ssubcat & "&county=" & scounty & "", True)

Thanks,

Seth Rowe

Thanks for the reply...I've tried using Server.transfer , and the True
attribute in the url string, still doesn't redirect
 
R

rowe_newsgroups

Thanks for the reply...I've tried using Server.transfer , and the True
attribute in the url string, still doesn't redirect

Ok, are you sure the redirect line is even executing? If not set a
breakpoint and step through the code and make sure. Also, can you
recreate this problem without the db query? As is I can't do any
debugging on my end which makes it much harder to find a solution.

Thanks,

Seth Rowe
 

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

Top