首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

怎么使用<% = %>代码

2012-09-27 
如何使用% %代码?前台页面courseContent.aspxHTML code%@ Page LanguageC# AutoEventWireuptrue

如何使用<% = %>代码?
前台页面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

热点排行