Using JavaScript to goto another aspx in ASP.NET


Using JavaScript I'd live to redicted my user to a difference aspx page in my ASP.NET 2.0 project within the same browser window.  Currently I have:

var oForm = document.forms[0];
oForm.action =  "Report.aspx?ReportType=" + reportType;

But that open a new browser.  I'd like this to be in the same browser.

Who is Participating?
Saqib KhanConnect With a Mentor Senior DeveloperCommented:
var oForm = document.forms[0];
oForm.action =  "Report.aspx?ReportType=" + reportType;
oForm.submit()  <--- Did you try this to submit?

Another way to do is is.

document.location = "Report.aspx?ReportType=" + reportType;

You can do above within the onClick event of a button (Client Side onClick)

eshurakAuthor Commented:
Thanks for your response.  I did not write this code so I'm not sure what's going on.

I left out the submit part.

       = '_reportWin';

If I comment out the target it stays in the same browser and I'm pretty happy with that.  I tried document.location but it gives me an error message so I'll stick with the oForm method.
Saqib KhanSenior DeveloperCommented:
> = '_reportWin';
in you orignal post you did not mention "target" line, target will open form in a new window. and yes that was the problem.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.