日期:2014-05-17  浏览次数:20432 次

如何使用<% = %>代码?
前台页面courseContent.aspx
HTML code

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="courseContent.aspx.cs" Inherits="teachingAndStudy.Public.courseContent" %>

<!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="../js/jq1.6.2.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $.post('getCourseMenus.ashx', 'who=<% =who %>', function (d) {

                });
            })
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div id='content'>
    </div>
    </form>
</body>
</html>




后台页面courseContent.aspx.cs
C# code

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

namespace teachingAndStudy.Public
{
    public partial class courseContent : System.Web.UI.Page
    {
        public string who = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                who = Request.QueryString["who"];
            }
        }
    }
}


前台页面中有下面的内容:
$.post('getCourseMenus.ashx', 'who=<% =who %>', function (d) {});

其中的who的值是其他页面传递过来的参数,如何将该参数传递给 jQuery 进行 post ? O(∩_∩)O谢谢~~~

------解决方案--------------------
你也可以这样写
$.post('getCourseMenus.ashx', 'who=<asp:Literal ID="Literal1" runat="server"></asp:Literal>', function (d) {});


后台
Literal1.Text = who