Hello All,
what is code for exceute one aspx page onclick hyperlink without dispaly that page?

Basically, I have one page p2.aspx.,which getting querystring parameter from page p1.aspx.
When I cliced on hyper link of p1.aspx page .it redirect to the p2.aspx.
but i want only that the code on p2.aspx excecute.and not need to dispaly p2.aspx page to user.

so what is the code on hyper link at p1.aspx in source file?

Thanking you,
Parimal.

Recommended Answers

All 3 Replies

ok i've made a Demo 4 you..

all you have to do is copy and paste..

This is the aspx code for my Default.aspx page..
As you can see in the javascript it calls the Default4.aspx page and
i've appended a data "Jigsaw" as a querystring..

in code behind there is not code..

<head runat="server">
    <title></title>

    <script src="PureAjax.js" type="text/javascript"></script>
    <script type="text/javascript" language="javascript">
        function MyMethod() {
            ajaxCall("POST", null, "Default4.aspx?name=jigsaw", "aa");
            return false;
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="ButtonX" runat="server" Text="Button" OnClientClick="MyMethod();return false;" />
    
    </div>
    <div id="aa">
    Testing Pure Ajax...
    </div>
    </form>
</body>
</html>

Let's move on to Default4.aspx page , on Design page add a Literal Control.
Done.

In code behind write the code...

protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["name"] != null)
        {
            Literal1.Text = "Name which you passed in was : " + Request.QueryString["name"].ToString();
        }
    }

as you can see it grabs the querystring name from the previous page and assigns value to Literal..
Done..

Final Js Code..you can Make a .jS and refrence to the Default.aspx page

var req;
function ajaxCall(p_submitMethod, p_parameters, p_url, p_targetDiv) {
    document.getElementById(p_targetDiv).innerHTML = 'loading data...';
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = function() { ajaxResponse(p_targetDiv); };

        if (p_submitMethod == "POST") {
            req.open("POST", p_url, true);
            req.send(p_parameters);
        }
        else {
            req.open("GET", p_url, true);
            req.send(null);
        }

    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = function() { ajaxResponse(p_targetDiv); };

            if (p_submitMethod == "POST") {
                req.open("POST", p_url, true);
                req.send(p_parameters);
            }
            else {
                req.open("GET", p_url, true);
                req.send();
            }


        }
    }
}


function ajaxResponse(p_targetDiv) {
    
    if (req.readyState == 4) {
    
        if (req.status == 200 || req.status == 304) {
            results = req.responseText;
            //alert(results); Use for Debugging...
            document.getElementById(p_targetDiv).innerHTML = results;

        } else {
            document.getElementById(p_targetDiv).innerHTML = "Some Error :" + req.statusText;
        }
    }
}

function createTimestamp() {
    return "timestamp=" + new Date().getTime().toString();
}

All Set...try this and let me know the output
hope that helps..!

Wow,Great ITs Really work very well and exactly that I waited...

Thank you So much ,Mr.Ashish.

wow seems like u did check my personal profile.. cool :)
but in these days it can be easily done via Jquery..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.