Handling back or refresh button in the browser

  • Thread starter Thread starter Krishna
  • Start date Start date
K

Krishna

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
 
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

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! |
*******************************************
 
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?
 
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).

Peace and Grace,

--
Gregory A. Beamer (MVP)

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

*******************************************
| Think outside the box! |
*******************************************
 
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
 
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.

Peace and Grace,

--
Gregory A. Beamer (MVP)

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

*******************************************
| Think outside the box! |
*******************************************
 
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>
 
any thoughts on my below ask?

Krishna said:
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>
 
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.

Peace and Grace,

--
Gregory A. Beamer (MVP)

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

*******************************************
| Think outside the box! |
*******************************************
 
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 :(?
================================================
<%@ 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:\\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">
<input type=submit runat="server">
<input type=button value="PC商å“一å¼" />
</form>
</body>
</html>
 
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?

Peace and Grace,



--
Gregory A. Beamer (MVP)

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

*******************************************
| Think outside the box! |
*******************************************
 
Back
Top