-4

please help me with this one question. so i have a page say page1.aspx, inside it has a link to another site. when i clicked on the link, it'd take me to another page that'd do some kindda validation, then redirects me back to the page i came from - page1.aspx - with the querystring, so then i'd ended up on the same page - same file name with a querystring - which is page1.aspx?messagestatus=fail, or page1.aspx?messagestatus=pass . then an alert box will pop and show a message depends on the status of the querystring (pass or fail)

The codes below works for me (i tested it by manually adding the ?messagestatus=pass or fail to the url), and i added the GetQString() function to the body onLoad. One problem is that I don't have access to the <body> tag to add that onload function, is there another way to activate that function without touching the <body> tag?

also, if you know of anything that works like this, but using a lightbox/modal box - please guide me there? thank you experts

here's my codes:

<!DOCTYPE>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
 <script type="text/javascript">
function querySt(Key) {
    var url = window.location.href;
    KeysValues = url.split(/[\?&]+/);
    for (i = 0; i < KeysValues.length; i++) {
            KeyValue= KeysValues[i].split("=");
            if (KeyValue[0] == Key) {
                return KeyValue[1];
        }
    }
}
</script>
<script type="text/javascript">
function GetQString(Key) {

    if (querySt("messagestatus")) {
         var value = querySt("messagestatus");
         //alert(value);
         if (value=='fail')
         {
            alert('Message:\nFailed!');
         }
         if (value=='pass')
         {
            alert('Message:\nPass!');        
         }
    }
 }
</script>

</head>

<body onload="GetQString();">
something here, <a href="#">this's the link that'll go out to another page, then redirects back to this page with the ?messagestatus=fail (or pass) querystring</a>.

</body>
</html>
tony
  • 91
  • 1
  • 1
  • 7
  • What have you tried so far, show us some code please. Or have a look [here](http://stackoverflow.com/questions/831030/how-to-get-get-request-parameters-in-javascript) – John Oct 31 '14 at 13:36
  • sorry about that, i just edited and added the codes...thanks – tony Oct 31 '14 at 19:21

1 Answers1

0

@tony..Capture the querystring and display message using the below code.

   string urlid = Request.QueryString["urlid"];
   if (urlid == "pass"){
   //Alert message
   }
   else if (urlid == "fail"){
   //Alert message
   }

For Alert message use one of the following code whichever works for you.

1. Page.ClientScript.RegisterStartupScript(Page.GetType(), "my", "alert('Pass');", true);
 
2. ClientScript.RegisterStartupScript(typeof(Page),"PopUp", "<script language='JavaScript'>window.alert('Pass');</script>");
TheGaME
  • 443
  • 2
  • 8
  • 21