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

救命啊!!!

asp.net中内容页后台如何调用母版页前台js方法 --------------------编程问答-------------------- http://edu.admin5.com/article/20101221/1221430112010.shtml


<%@ 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 type="text/javascript">        
        function TestValue()
        {
            var str = "这是测试的输入值";
            UseCallback(str);
        }
        
        function GetValye(value)
        {
            document.getElementById("TextBox1").value = value;
        }
    </script>
</head>
<body onload="TestValue();">
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    </div>
    </form>
</body>
</html>

后台C#代码:
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page, System.Web.UI.ICallbackEventHandler
{
    string callback = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        string strRefeence = Page.ClientScript.GetCallbackEventReference(this, "arg", "GetValye", "content");
        string strScript = "function UseCallback(arg, content){" + strRefeence + ";}";
        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "UseCallback", strScript, true);
    }

    public void RaiseCallbackEvent(string eventArg)
    {
        if (eventArg.Equals("这是测试的输入值"))
        {
            callback = "传值正确";
        }
        else
        {
            callback = "传值错误";
        }
    }

    public string GetCallbackResult()
    {
        return callback;
    }

--------------------编程问答-------------------- 这个问题关键是内容页与母版页间的调用!谢谢! --------------------编程问答-------------------- --------------------编程问答-------------------- 学习一下
支持一下 --------------------编程问答-------------------- 正常调用 或在内容页自己引入js --------------------编程问答--------------------  问题就是怎么调用呢? --------------------编程问答--------------------
引用 6 楼 luckgirljing 的回复:
 问题就是怎么调用呢?


你把母板页中的脚本方法写到JS文件,引用就好了,然后再别的页面就可以引用该母板页下的JS方法 --------------------编程问答--------------------
<%@ Master Language="C#" AutoEventWireup="true" Codebehind="DL0.master.cs" Inherits="Slife.SHCMA.UI.DL0.DL0" %>

<!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 type="text/javascript" src="../Javascript/dojo/dojo.js"></script>


如引用dojo,然后再其他页面也可以调用dojo中的方法 --------------------编程问答-------------------- 非要用母版页啊,换DIV+CSS看看 --------------------编程问答-------------------- <script language="javascript" type="text/javascript" src="<%=Page.ResolveClientUrl("~/JavaScripts/jquery.js") %>"></script>   --------------------编程问答-------------------- 你是不是搞错了,哪有后台服务端调用客户端JS的,JS调用后台服务端还差不多 --------------------编程问答-------------------- 恩 学习了。。。。。 --------------------编程问答-------------------- 好像不能调用吧?直接将母版页中的JS方法写到一个JS文件中,然后母版页和子页面中都来调用多好呢?这样客户端也看不到你的源代码,建议LZ将JS方法存放到JS文件中,在各页面中调用,你那么写是不规范的。
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,