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

请问怎么前台调用后台代码(简单)

2012-03-18 
请教如何前台调用后台代码(简单)前台代码如下:C# code%@ Page LanguageC# AutoEventWireuptrue Cod

请教如何前台调用后台代码(简单)
前台代码如下:

C# code
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm7.aspx.cs" Inherits="Test.WebForm7" %><!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 id="Head1">    <title></title>    <link href="Css/default.css" rel="stylesheet" type="text/css" />    <link rel="stylesheet" type="text/css" href="js/themes/default/easyui.css" />    <link rel="stylesheet" type="text/css" href="js/themes/icon.css" />    <script type="text/javascript" src="js/jquery-1.4.1.min.js"></script>    <script type="text/javascript" src="js/jquery.easyui.js"></script>    <script type="text/javascript" src='js/outlook2.js'> </script>    <script type="text/javascript">        var _menus = { "menus": [                    "<%=fun()%>"//                                    {'menuid': '1', 'icon': 'icon-sys', 'menuname': '门诊处方',//                                    "menus": [{ "menuname": "菜单管理", "icon": "icon-nav", "url": "http://hxling.cnblogs.com" },//                                                { "menuname": "添加用户", "icon": "icon-add", "url": "demo.html" },//                                                { "menuname": "用户管理", "icon": "icon-users", "url": "demo2.html" },//                                                { "menuname": "角色管理", "icon": "icon-role", "url": "demo2.html" },//                                                { "menuname": "权限设置", "icon": "icon-set", "url": "demo.html" },//                                                { "menuname": "系统日志", "icon": "icon-log", "url": "demo.html" }//                                           ]//                    }, { "menuid": "28", "icon": "icon-sys", "menuname": "财务管理",//                        "menus": [{ "menuname": "收支分类", "icon": "icon-nav", "url": "demo2.html" },//                                                { "menuname": "报表统计", "icon": "icon-nav", "url": "demo2.html" },//                                                { "menuname": "添加支出", "icon": "icon-nav", "url": "demo2.html" }//                                            ]//                    }                ]        };



后台代码如下:
C# code
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;namespace Test{    public partial class WebForm7 : System.Web.UI.Page    {        protected void Page_Load(object sender, EventArgs e)        {        }        public String get()        {            return "门诊处方";        }        public void fun()        {            String x = "{ 'menuid': '1', 'icon': 'icon-sys', 'menuname': '门诊处方',"                            + "'menus': [{ 'menuname': '菜单管理', 'icon': 'icon-nav', 'url': 'http://hxling.cnblogs.com' },"                                    + "{ 'menuname': '添加用户', 'icon': 'icon-add', 'url': 'demo.html' },"                                    + "{ 'menuname': '用户管理', 'icon': 'icon-users', 'url': 'demo2.html' },"                                    + "{ 'menuname': '角色管理', 'icon': 'icon-role', 'url': 'demo2.html' },"                                    + "{ 'menuname': '权限设置', 'icon': 'icon-set', 'url': 'demo.html' },"                                    + "{ 'menuname': '系统日志', 'icon': 'icon-log', 'url': 'demo.html' }]},"                         + "{ 'menuid': '28', 'icon': 'icon-sys', 'menuname': '财务管理',"                         + "'menus': [{ 'menuname': '收支分类', 'icon': 'icon-nav', 'url': 'demo2.html' },"                        + "{ 'menuname': '报表统计', 'icon': 'icon-nav', 'url': 'demo2.html' },"                        + "{ 'menuname': '添加支出', 'icon': 'icon-nav', 'url': 'demo2.html' }]}";            Response.Write(x);        }        //public String fun()        //{        //    return "{ 'menuid': '1', 'icon': 'icon-sys', 'menuname': '门诊处方',"        //                    + "'menus': [{ 'menuname': '菜单管理', 'icon': 'icon-nav', 'url': 'http://hxling.cnblogs.com' },"        //                            + "{ 'menuname': '添加用户', 'icon': 'icon-add', 'url': 'demo.html' },"        //                            + "{ 'menuname': '用户管理', 'icon': 'icon-users', 'url': 'demo2.html' },"        //                            + "{ 'menuname': '角色管理', 'icon': 'icon-role', 'url': 'demo2.html' },"        //                            + "{ 'menuname': '权限设置', 'icon': 'icon-set', 'url': 'demo.html' },"        //                            + "{ 'menuname': '系统日志', 'icon': 'icon-log', 'url': 'demo.html' }]},"        //                 + "{ 'menuid': '28', 'icon': 'icon-sys', 'menuname': '财务管理',"        //                 + "'menus': [{ 'menuname': '收支分类', 'icon': 'icon-nav', 'url': 'demo2.html' },"        //                + "{ 'menuname': '报表统计', 'icon': 'icon-nav', 'url': 'demo2.html' },"        //                + "{ 'menuname': '添加支出', 'icon': 'icon-nav', 'url': 'demo2.html' }]}";        //}    }} 




意思很简单,就是想动态实现前台页面中的内容:比如把门诊处方换成aaa或者bbb这样的。毕竟这些数据是从数据库中取出来的。请教有什么好的方法实现吗?"<%=fun()%>"脚本的方法,和我注释掉的方法都不行。实验过了。
顺便申明下,前台的代码是jquery的。大家帮帮忙吧。谢谢了~ :P

[解决办法]
<script type="text/javascript">
var _menus = { "menus": [<%=fun()%>]};
</script>
[解决办法]

public string str="";

protected void Page_Load(object sender, EventArgs e)
{
str=fun();
}
public string fun()
{
String x = "{ 'menuid': '1', 'icon': 'icon-sys', 'menuname': '门诊处方',"
+ "'menus': [{ 'menuname': '菜单管理', 'icon': 'icon-nav', 'url': 'http://hxling.cnblogs.com' },"
+ "{ 'menuname': '添加用户', 'icon': 'icon-add', 'url': 'demo.html' },"
+ "{ 'menuname': '用户管理', 'icon': 'icon-users', 'url': 'demo2.html' },"
+ "{ 'menuname': '角色管理', 'icon': 'icon-role', 'url': 'demo2.html' },"
+ "{ 'menuname': '权限设置', 'icon': 'icon-set', 'url': 'demo.html' },"
+ "{ 'menuname': '系统日志', 'icon': 'icon-log', 'url': 'demo.html' }]},"
+ "{ 'menuid': '28', 'icon': 'icon-sys', 'menuname': '财务管理',"
+ "'menus': [{ 'menuname': '收支分类', 'icon': 'icon-nav', 'url': 'demo2.html' },"
+ "{ 'menuname': '报表统计', 'icon': 'icon-nav', 'url': 'demo2.html' },"
+ "{ 'menuname': '添加支出', 'icon': 'icon-nav', 'url': 'demo2.html' }]}";
return x;
}



<script type="text/javascript">

 var _menus = { "menus": [
"<%=str%>"]}
</script>


热点排行