Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Response.Redirect is causing some code to skip...? 3

Status
Not open for further replies.

AT76

Technical User
Apr 14, 2005
460
US
Hi,

I'm trying to understand why Response.Redirect causes some of my code to be skipped redirecting to the page assigned. I have a button that when click is supposed to due some date validations and Warranty validations. Both of these work fine without adding Response.Redirect to void btnSubmit_Click. But when I do added to the code it causes some of the code in WarrantyValidation() to not be activated and it completely ignores WarrantyValidation(). Is there a reason for this?

Thanks!!!


private void btnSubmit_Click(object sender, System.EventArgs e)
{
DateValidation();
WarrantyValidation();
Response.Redirect("EnterNewData.aspx");
}
 
It doesn't matter if controls are outputted or not. The RegisterStartUpScript and RegisterClientScript functions have been created to be used exactly for the purpose of what the user wants to do.

Response.Write is a deprecated function and that is why it shouldn't be recommended. Surely you can see the reason why we shouldn't be recomminding functions that are left over from legacy versions of the programming language and have been replaced?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Thanks for your input ca8msm. From what you mentioned, how would you modify line of code: Response.Write("location.href='EnterNewData.aspx'"); ??

 
If it's just a simple script that you want to run on the load of the page, you would just call the Page.RegisterStartUpScript and pass in a key for the script as the first argument, and the actual script as a String for the second argument.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Can't you use this...

Code:
Response.Redirect("EnterNewData.aspx",[blue]False[/blue])

The second parameter "Indicates whether execution of the current page should terminate")
 
>> Surely you can see the reason why we shouldn't be recomminding functions that are left over from legacy versions of the programming language and have been replaced?

ok, agreed, but now this gives me another problem.

in certain screens lets say i want to just print plain text (like a Hi) and end the execution of the progam (for which i use a response.end()).

the entire idea there is to not output ANY HTML whatsoever, just the plain text.

how do i go about doing that in .NET???

Known is handfull, Unknown is worldfull
 
the entire idea there is to not output ANY HTML whatsoever, just the plain text.
Well that would create a semantically invalid page to start with so I wouldn't suggest doing that. For example, if you want to write something out to the page, it should be enclosed in the relevant HTML tags (i.e. if it's a header use <h1>, if it's a paragraph of text use <p> tags etc...).

However, if you want to continue down the semantically incorrect route and not do any of this, you would simply use a Literal control and not wrap any tags around it. e.g.
Code:
Dim l as New Literal
l.Text = "Hi"
PlaceHolder1.Controls.Add(l)



____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
>>Well that would create a semantically invalid page to start with so I wouldn't suggest doing that

that us because this output is read by another software (director), i will not be able to implement webservices in this project because of restrictions.

for director to read the output the page must output plain text like this (in querystring format):

Hi=1&Val=2

there must be absolutely NO html. if i use .NET controls then there is a problem...

Known is handfull, Unknown is worldfull
 
there must be absolutely NO html. if i use .NET controls then there is a problem...
No there isn't a problem. You would simply use a Literal control like I suggested above.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Sorry, I think I may have mis-interpreted exactly what you want. When you say you want no HTML, do you mean you don't want a DOCTYPE, html, body form tags etc?

If so, then this isn't a valid HTML page anyway as (unless you've changed it) the ContentType will still be sent as "text/html" which is won't be due to the omissions of those tags.

If you simply want a page that can be called by an external application that returns a string (and you can't use web services) is use the fairly similar Response.WriteFile (as the text can then be stopred seperately to the applciation and it can be changed without re-deploying the application). Also, remember to change the ContentType to "text/plain" first.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
In fact, scrap that idea above as an even better implementation would be to use a generic handler file (ashx). In this case, Response.Write would be acceptable as you are not writing to the Page class. e.g.

myHandler.ashx
Code:
<%@ WebHandler Language="VB" Class="Handler" %>

Imports System
Imports System.Web

Public Class Handler : Implements IHttpHandler
    
    Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
        context.Response.ContentType = "text/plain"
        context.Response.Write("Hi")
    End Sub
 
    Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property

End Class


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
yes, but u had to use Response.write there, i want to avoid that, but i like the Handler idea...

Known is handfull, Unknown is worldfull
 
yes, but u had to use Response.write there, i want to avoid that, but i like the Handler idea...
Yes, but if you read what I said, I stated "In this case, Response.Write would be acceptable as you are not writing to the Page class".


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
hmm, but i thought deprecated / legacy functions will be removed as the versions procede??? thats wht i am worried bout...

Known is handfull, Unknown is worldfull
 
No, Response.Write won't be removed from future versions (AFAIK). What I meant by deprecated/legacy functions was your implementation of this function in writing out JavaScript to a Page (i.e. it was used in classic ASP but now other functions have been created to replace it's use within actual pages). It will still be a valid method as long as it is used appropiately and in the correct context.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top