当前位置:编程学习 > C#/ASP.NET >>

Is there a simple way to transfer data between client and server?

I use HiddenField1 control to transfer data between client and server. First I click Button1,then click Button2, the text of Button2 will be set as "cc" 
but I think it's too complex, is there a simple way? Thanks!


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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">
<head runat="server">
    <title></title>
    <script src="jquery1.4.2.min.js" type="text/javascript"></script>
   
    <script type="text/javascript">
        $(function () {
            $("#Button1").click(function () {
                $("#HiddenField1").val("bb");
            });
        });
    </script>
</head>

<body>
    <form id="form1" runat="server">
    <div>    
        <asp:HiddenField ID="HiddenField1" runat="server" ClientIDMode="Static" />
        <br />
        <br />
        <input id="Button1" type="button" value="button" />   
        <asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="Button" />
    </div>
    </form>
</body>
</html>



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        Button2.Text = HiddenField1.Value;
    }

} --------------------编程问答--------------------  $(function () {
  $("#Button1").click(function () {
  $("#HiddenField1").val("bb");
  $("#Button2").val()=$("#HiddenField1").val();
  });
  }); --------------------编程问答-------------------- 谢谢!

我问是除了使用HiddenField1,是否还有其它技术传递数据 --------------------编程问答-------------------- cookies session 都可以啊 --------------------编程问答-------------------- if u just want to change the text of Button2, u can simply do it like this:
  <script type="text/javascript">
  $(function () {
  $("#Button1").click(function () {
  $("#Button2").val($("#Button1").val());
  });
  });
  </script>

if u r looking another way to transfer data from client to server, u can put the data of string type into the url as a query string, or u can also use AJAX. --------------------编程问答-------------------- think out loud, and you will get a better answer....... --------------------编程问答-------------------- 英盲飘过 --------------------编程问答--------------------
引用 6 楼 posefooler 的回复:
英盲飘过

+1 --------------------编程问答-------------------- To lerualbye

Javascript 能操作cookies session吗? --------------------编程问答-------------------- Javascript 能操作cookies session吗? --------------------编程问答-------------------- 1、后台定义公共变量,前台可以用 var obj='<%=stringname%>'; 接到值。
2、js是可以操作cookies session的 --------------------编程问答-------------------- first:session is Server-side,How to change in the client?
second:Re-define a cookies and ID the same,Previous coverage,Like with the change。 --------------------编程问答--------------------
引用 10 楼 maco_wang 的回复:
1、后台定义公共变量,前台可以用 var obj='<%=stringname%>'; 接到值。
2、js是可以操作cookies session的


客户端搞不到session的值吧。 --------------------编程问答-------------------- To maco_wang
你能给出一个例子代码吗? --------------------编程问答-------------------- Jquery.Ajax() 可以操作Cookie 。。。 Session 目前還不行 --------------------编程问答-------------------- ICallBackEventHandler
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,