簡體   English   中英

如何從另一個ASPX頁面內引用MasterPage中的JavaScript代碼

[英]How to reference JavaScript code in MasterPage from within another aspx page

一個簡單的問題:如何從我的一個ASPX頁面中引用一個母版頁文件(與許多其他ASPX頁位於同一文件夾中)上的JavaScript代碼?

母版頁

    <%@ Master Language="C#" AutoEventWireup="true" CodeFile="JobRegister.master.cs" Inherits="JobRegister_Job" %>

    <!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>Tec-NQ miJob Register</title>
        <style type="text/css">
        textarea { font-family: Arial; font-size: 10pt; }
        a { white-space: nowrap; }
        .tablestyle { background-color:#eeeeee; width:100%; margin-bottom:2px; padding:3px; }
        .checkboxlist input { position:relative; left: 360px; }
        .checkboxlist label { position:relative; left: -22px; }
        .hidepanel { display: none; }
        .showpanel { display: block; }
        </style>

        <script src="<%# ResolveUrl("~/") %>" type="text/javascript">
            /*
                Added : Variables required for image uploading & validation checking.
                By : Amit Champaneri
                On : 4th April 2008
            */
            var hoverColor = "#00000b"; //DIV Color when mouse is hover the DIV
            var defaultColor = "black"; //DIV default color
            var selectColor = "#000000"; // DIV color when its selected.
            var selectedDIV = "";        //ID of the DIV user has currently selected(it will be 1,2,3 or 4)                
            var objActiveX; //Object of Clipboard ActiveX control.
..
..etc..

我的ASPX頁面對母版頁中的Java語言有引用。

ASPX頁面

<%@ Page Language="C#" MasterPageFile="~/JobRegister/JobRegister.master" AutoEventWireup="true" CodeFile="Details.aspx.cs" Inherits="JobRegister_Details" %>
<%@ Register TagPrefix="tecnq" TagName="JobAction" Src="ActionControl.ascx" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1" DataKeyNames="JobID, CreatedBy" GridLines="None" 
        AllowPaging="True" DefaultMode="Edit" OnDataBound="FormView1_OnDataBound" OnItemCreated="FormView1_OnItemCreated"
        OnItemUpdated="FormView1_OnItemUpdated" OnItemUpdating="FormView1_Updating"
        HeaderText="Job Details" CellPadding="0" Font-Names="Arial" Font-Size="10pt">
        <HeaderStyle BackColor="#5D7B9D" ForeColor="White" Font-Bold="True" HorizontalAlign="Center" Height="30px" />
        <InsertItemTemplate>
...
..etc..
...
<img id="imgPaste1" src="Images/imgPaste.gif" class="LinkImage" title="Click here to Paste any copied Image" onclick="javascript:pasteOnClick('1');" />
..
..etc..
..

我從一個很棒的博客中獲得了所有關於如何將剪貼板圖像粘貼到Web表單中的信息...

http://www.codeproject.com/Articles/25967/Clipboard-ActiveX-for-Image-Copy-Paste-into-Web-Fo

上面博客中的演示效果很好,但是Javascript和ASPX代碼都在同一個文件中!

如何使用MasterPage中的Javascript進行相同操作,並在ASPx文件中引用這些腳本?

我也嘗試將所有代碼放在我的ASPX文件中,但是在此行代碼上收到無效的引用錯誤...

document.getElementById("<%=hdnImageFileName1.ClientID %>").value = "";

就是說它找不到對“ hdnImageFileName1”的引用,但我知道它在我的ASPX頁面中……

<asp:HiddenField runat="server" ID="hdnImageFileName1" />

提前致謝。

答案就像@deostroll說的那樣。 我將所有JS代碼移到了custom.js文件中,並僅通過標記對其進行了引用。 簡單。 做完了! 謝謝

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM