Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将值从jquery模式弹出窗口发送到父级时出现问题_C#_Jquery_Asp.net_Modal Dialog - Fatal编程技术网

C# 将值从jquery模式弹出窗口发送到父级时出现问题

C# 将值从jquery模式弹出窗口发送到父级时出现问题,c#,jquery,asp.net,modal-dialog,C#,Jquery,Asp.net,Modal Dialog,下面是我的代码 您能告诉我如何将此页面上的label1.text发送到product.aspx并更新label1.text product.aspx <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <link href="styles/modal-window.css" type="text/css" rel

下面是我的代码

您能告诉我如何将此页面上的label1.text发送到product.aspx并更新label1.text

product.aspx

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
     <title></title>
     <link href="styles/modal-window.css" type="text/css" rel="stylesheet" />
     <script type="text/javascript" language="javascript" src="scripts/jquery-1.3.2.min.js"></script>
     <script type="text/javascript" language="javascript" src="scripts/modal-window.min.js"></script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="Label1" runat="server" Text="0"></asp:Label>
        <br />
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" 
            Text="icrement" />
        <a href="viewcart.aspx?fn=<%= Label1.Text %>" onclick="$(this).modal({width:833, height:453}).open(); return false;">show popup</a>
    </div>
    </form>
</body>
</html>
viewcart.aspx

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
      </head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" Text="decrement" 
            onclick="Button1_Click" />
        <br />
        current value: 
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    </div>
    </form>
</body>
</html>

您可以将asp:HiddenField控件添加到页面,通过javascript设置其值,然后将其发回您的codebehind。

如果您想要好的答案,请尝试以更一般的方式提出问题。label和HiddenField之间有什么区别??label呈现为,其内容不会发回代码behind,而HiddenField被呈现为表单的一部分,并且是表单的一部分,并且值被传递回代码隐藏。
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
      </head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" Text="decrement" 
            onclick="Button1_Click" />
        <br />
        current value: 
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    </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 viewcart : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            Label1.Text = Request["fn"];
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Label1.Text = (int.Parse(Label1.Text) - 1).ToString();
    }
}