码迷,mamicode.com
首页 > 其他好文 > 详细

ggg

时间:2016-11-05 23:44:14      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:xmlns   w3c   exp   org   pre   public   rgs   nts   copy   

          __doPostBack(‘SetSessionPostBack‘, newValue);
        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <input id="Button1" type="button" value="button" onclick="setSessionValue(‘hello‘);" /><div>
    </div>
    </form>
</body>
</html>
技术分享

 

方法二:

使用AJAX

技术分享
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    private void Page_Load(object sender, System.EventArgs e)
    {
        if (!this.IsPostBack)
        {
            this.Session["SessionValue"] = "Original value";
        }

        this.Response.Write("SessionValue: " + this.Session["SessionValue"].ToString() + "<br>");
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

    <script type="text/javascript">

        function makeAjaxCall(webUrl, queryString) {
            var xmlHttpObject = null;

            try {
                // Firefox, Opera 8.0+, Safari技术分享

                xmlHttpObject = new XMLHttpRequest();
            }
            catch (ex) {
                // Internet Explorer技术分享

                try {
                    xmlHttpObject = new ActiveXObject(‘Msxml2.XMLHTTP‘);
                }
                catch (ex) {
                    xmlHttpObject = new ActiveXObject(‘Microsoft.XMLHTTP‘);
                }
            }

            if (xmlHttpObject == null) {
                window.alert(‘AJAX is not available in this browser‘);
                return;
            }

            xmlHttpObject.open("GET", webUrl + queryString, false);
            xmlHttpObject.send();

            var xmlText = xmlHttpObject.responseText;

            return xmlText;
        }

        function setSessionValue(newValue) {
            var webUrl = ‘AjaxPage.aspx‘;
            var queryString = ‘?SessionValue=‘ + newValue;
            var returnCode = makeAjaxCall(webUrl, queryString);
            //alert(returnCode);
            <%= ClientScript.GetPostBackEventReference(this, string.Empty) %>;
        }

    </script>

</head>
<body>
    <form id="form1" runat="server">
    <input id="Button1" type="button" value="button" onclick="setSessionValue(‘Lance Zhang‘);" /><div>
    </div>
    </form>
</body>
</html>

ggg

标签:xmlns   w3c   exp   org   pre   public   rgs   nts   copy   

原文地址:http://www.cnblogs.com/ZSLL/p/6034197.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!