Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Handling back or refresh button in the browser

2 views
Skip to first unread message

Krishna

unread,
Dec 10, 2009, 2:02:01 AM12/10/09
to
I've an asp.net application, when the user click on back or refresh button, i
want the user to be redirected to a default.aspx always irrespective where he
was. What is the simplest and best way to accomplish this

Mark Rae [MVP]

unread,
Dec 10, 2009, 5:39:25 AM12/10/09
to
"Krishna" <Kri...@discussions.microsoft.com> wrote in message
news:68E6EEA3-D8D2-4491...@microsoft.com...

> I've an ASP.NET application, when the user click on back or refresh
> button, I


> want the user to be redirected to a default.aspx always irrespective where
> he
> was. What is the simplest and best way to accomplish this

You have (almost) no chance of doing this. The back, forward and refresh
buttons are part of the web browser and, as such, web applications have
essentially no control over them.

This is about as good as you'll get:
http://www.4guysfromrolla.com/webtech/111500-1.shtml


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Gregory A. Beamer

unread,
Dec 10, 2009, 1:13:29 PM12/10/09
to
=?Utf-8?B?S3Jpc2huYQ==?= <Kri...@discussions.microsoft.com> wrote in
news:68E6EEA3-D8D2-4491...@microsoft.com:

Simplest and best is popup a form with no back button. :-)

See if this helps:
http://tinyurl.com/ybksoyd

It is not exhaustive, so a good Google search for more complete scripts,
etc, might be in order. I also need to put together a sample of how to
pattern ASP.NET to minimize back button horrors, but I don't have time
now.

Peace and Grace,

--
Gregory A. Beamer (MVP)

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************

Krishna

unread,
Dec 11, 2009, 2:20:01 AM12/11/09
to
thanks a lot. But ive posted one more query , but i haven't got any response,
hence pasting my query here.

I have a asp.net page in which i have set the responseencoding
"WINDOWS-1252" it converts all the characters displayed from UTF-8 to
WINDOWS-1252. but i need to use WINDOWS-1252 as encoding type to post a
data to a server, but the display should remain in UTF-8. Like display all the
controls in UTF-8 when i click a button i need to convert the data from
UTF-8 to WINDOWS-1252 and post the data to server during postback is that
possible?

will yoy guys help?

"Gregory A. Beamer" wrote:

> .
>

Gregory A. Beamer

unread,
Dec 11, 2009, 11:19:33 AM12/11/09
to
=?Utf-8?B?S3Jpc2huYQ==?= <Kri...@discussions.microsoft.com> wrote in
news:BAACE263-1AB3-43C0...@microsoft.com:

> I have a asp.net page in which i have set the responseencoding
> "WINDOWS-1252" it converts all the characters displayed from UTF-8 to
> WINDOWS-1252. but i need to use WINDOWS-1252 as encoding type to post
> a data to a server, but the display should remain in UTF-8. Like
> display all the controls in UTF-8 when i click a button i need to
> convert the data from UTF-8 to WINDOWS-1252 and post the data to
> server during postback is that possible?

I have not seen this before. It would be easy enough to map from UTF-8
to Windows-1252 in binary, however.

http://dev.networkerror.org/utf8/
http://en.wikipedia.org/wiki/Windows-1252

I know it would be a bit of a pain, but chances are you are only using a
small number of characters out of the set, so you don't have to map
everything. In addition, the Windows-1252 char set only gives 256
characters (including null (0), so that is all you really have to map
for most instances).

Krishna

unread,
Dec 14, 2009, 4:00:01 AM12/14/09
to
what do you mean when u say "It would be easy enough to map from UTF-8
to Windows-1252 in binary"

Can you gimme a sample with my scenario as an example

"Gregory A. Beamer" wrote:

> .
>

Gregory A. Beamer

unread,
Dec 14, 2009, 10:10:26 AM12/14/09
to
=?Utf-8?B?S3Jpc2huYQ==?= <Kri...@discussions.microsoft.com> wrote in
news:4FBBFE82-4CD8-4851...@microsoft.com:

> what do you mean when u say "It would be easy enough to map from UTF-8
> to Windows-1252 in binary"
>
> Can you gimme a sample with my scenario as an example

I just found a simpler method:
http://snurl.com/tokx9

The example goes from 1252 to UTF-8, but flipping some of the statements
should solve the problem.

Krishna

unread,
Dec 15, 2009, 2:03:01 AM12/15/09
to
I've attached a sample.aspx content, i've already doing a character
conversion from SHIFT-JIS to windows-1252, i've set responseconding to
'windows-1252' to post the data (rightclick on IE and encoding is western
european). but when i do that the , button which has japan text comes as
question mark... so what i need is that post with windows 1252 and have the
button display in same as displayed in the page.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" ResponseEncoding="windows-1252"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"_http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="_http://www.w3.org/1999/xhtml">
<script language="C#" runat="server">

public string in_simei_sei
{
get
{
string test = "陳";
Encoding nav = Encoding.GetEncoding(1252);;
Encoding unicode = Encoding.GetEncoding(932);
byte[] unicodeBytes = unicode.GetBytes(test);
return nav.GetString(unicodeBytes);
}
}
</script>
<script language="javascript" type="text/javascript">

function add(type, value) {
try {

var element = document.createElement("input");
element.setAttribute("type", type);
element.setAttribute("value", value);
element.setAttribute("name", type);
element.setAttribute("visible", false);
var foo = document.forms[0];
foo.appendChild(element)

}
catch (err) {
var txt = "There was an error on this page.\n\n";
txt += "Error description: " + err.description + "\n\n";
txt += "Click OK to continue.\n\n";

alert(txt)
return;
}
}

function postData()
{
try {

add("in_simei_sei", "<%=in_simei_sei%>");
}
catch(err)
{
var txt = "There was an error on this page.\n\n";
txt += "Error description: " + err.description + "\n\n";
txt += "Click OK to continue.\n\n";
return;
}
var xmlhttp = null;
if (window.XMLHttpRequest) {
// code for Firefox, Mozilla, IE7, etc.
try
{
xmlhttp = new XMLHttpRequest(); // instantiate it
}
catch (err)
{
alert("Error initializing XMLHttpRequest.\n" + err); // show
error
}
}
else if (window.ActiveXObject)
{

var msobj = new Array( "Msxml2.XMLHTTP.6.0",
"Msxml2.XMLHTTP.4.0",
"Msxml2.XMLHTTP.3.0",
"Msxml2.XMLHTTP",
"Microsoft.XMLHTTP");

var x, len = msobj.length;
for (x = 0; x < len; ++x)
{
try
{
xmlhttp = new ActiveXObject(msobj[x]);
break;
}
catch (err)
{
alert("Error initializing XMLHttpRequest : IE : \n" +
err.message); // show error
};
}
alert("inside else")
}
var processingUrl = "http://www.google.com";

try
{
xmlhttp.open("POST", processingUrl,true); ; // open server
interface
}
catch (err)
{
var txt = "There was an error on this page.\n\n";
txt += "Error description: " + err.description + "\n\n";
txt += "Click OK to continue.\n\n";
// alert(txt);
return;
}

if (xmlhttp.readyState == 1)
{
try
{
xmlhttp.send(c_var);
}
catch (z)
{
alert(z)
}
}

//
}
</script>
</head>
<body>

<form id="Form1" runat="server" onsubmit="postData();" method="post"
action="http://www.google.com">
<input type=submit runat="server">
<input type=button value="PC商品一式" />
</form>
</body>
</html>

Krishna

unread,
Dec 23, 2009, 5:03:01 AM12/23/09
to
any thoughts on my below ask?

Gregory A. Beamer

unread,
Dec 23, 2009, 10:47:18 AM12/23/09
to
=?Utf-8?B?S3Jpc2huYQ==?= <Kri...@discussions.microsoft.com> wrote in
news:8637DF17-C7E1-4D9F...@microsoft.com:

> any thoughts on my below ask?

Let's step back. Looking at the page, it looks like you are setting up a
form submit to google. Is that your goal? Submit to Google and get a valid
search?

Rather than "how to I solve the problem in the manner I am already trying
to solve it" let's get to "how do I solve the problem". So, what is the
goal. Not the goal plus the proposed solution, but a simple statement of
what the actual problem is.

Krishna

unread,
Dec 24, 2009, 5:50:01 AM12/24/09
to
ok. Lets say i want to post the data to a
http:\\localhost\mysite\default.aspx.

when i cut paste the below code and put in sample.aspx and run it, right
click in IE , it has encoding as western european coz i've set
responseencoding as 'windows-1252' right.

My question is :
Page has a button <input type=button value="PC商品一式" /> with Japenese text,
which comes as ?????, i hope u have noticed it when type in sample.aspx in
the browser. SO my question is i want the japaenese text button remains as it
is and i wanna choose encoding as 'western european' to post the data when i
click the submit button. is my question clear :(?
================================================

function postData()
{
try {

var processingUrl = "http:\\localhost\mysite\default.aspx";



try
{
xmlhttp.open("POST", processingUrl,true); ; // open server
interface
}
catch (err)
{
var txt = "There was an error on this page.\n\n";
txt += "Error description: " + err.description + "\n\n";
txt += "Click OK to continue.\n\n";
// alert(txt);
return;
}

if (xmlhttp.readyState == 1)
{
try
{
xmlhttp.send(c_var);
}
catch (z)
{
alert(z)
}
}

//
}
</script>
</head>
<body>

<form id="Form1" runat="server" onsubmit="postData();" method="post"

action="http:\\localhost\mysite\default.aspx">

Gregory A. Beamer

unread,
Dec 28, 2009, 10:14:49 AM12/28/09
to
=?Utf-8?B?S3Jpc2huYQ==?= <Kri...@discussions.microsoft.com> wrote in
news:B7FFC85E-74A6-4E19...@microsoft.com:

> Page has a button <input type=button value="��� ņ" �� �� " />


> with Japenese text, which comes as ?????, i hope u have noticed it
> when type in sample.aspx in the browser. SO my question is i want the
> japaenese text button remains as it is and i wanna choose encoding as
> 'western european' to post the data when i click the submit button. is
> my question clear

Is the button the only problem? If the button simply has to be in
Japanese, but all submissions need to be in 1252, then why not make an
image with the japanese characters and leave everything else 1252. This
will solve the button is not Japanese problem, if that is truly the
problem. ImageButton works nicely here and is much simpler than
translating the button.

If the main issue is output of the button on an otherwise 1252 page, you
are always going to have an issue. And if you are setting up the page as
Japanese and trying to convert, that might be a more complex solution
than needed.

Is the text entered Japanese? And, do you have to recreate it as
Japanese later?

Is storing in a database a problem? And, if so, can you change to
national variable character (2 byte, or Unicode) insted of variable
character (1 byte, or ANSI - ASCII if you wish)?

Or, perhaps you are really aiming at globalizing the application? If so,
there are numerous additions that allow for globalizing the application.

The main point of translating from one code page to another, or ANSI to
Unicode, etc, is the persistence of data. In a windows app, it could be
taking a Unicode file and saving as ANSI. In a web app, it might be
saving as varchar in SQL Server when the page is Unicode. But making a
whole page Japanese so you can make the button correct and then
converting everything to another code page to save in English goes
contrary to the way the system is meant to operate.

Am I hitting on the right direction, or did I miss something?

0 new messages