javascript - 我如何在一个 aspx 页面上对每个用户控件使用 javascript pageLoad() 事件?

标签 javascript asp.net user-controls asp.net-ajax

我有一个带有多个用户控件的 aspx 页面。 页面是这样的,

<asp:Content ID="Content2" ContentPlaceHolderID="chpMainBody" runat="server">

            <en:ProfileInfo ID="ucProfileInfo" runat="server" />

            <br />
             <en:WorkingExperienceInfo ID="ucWorkingExperienceInfo" runat="server" />
            <br />
              <en:TechnicalInfo ID="ucTechnicalInfo" runat="server" />

   <br />
           <en:EducationInfo ID="ucEducationInfo" runat="server" />
</asp:Content>

我在每个用户控件中使用此脚本,用于带有 TreeView 的 dropdownextender,这是用于“ucEducationInfo”用户控件

<script type="text/javascript">
    var DDE4;
    var DDE5;
    function pageLoad() {
        DDE4 = $find('<%= dde_CountryUniversity.ClientID %>');
        DDE5 = $find('<%= dde_UniversityMajors.ClientID %>');


        DDE4._dropWrapperHoverBehavior_onhover();
        DDE5._dropWrapperHoverBehavior_onhover();

        $get('<%= pnl_CountryUniversity.ClientID %>').style.width = $get('<%= txt_CountryUniversity.ClientID %>').clientWidth;
        $get('<%= pnl_UniversityMajors.ClientID %>').style.width = $get('<%= txt_UniversityMajors.ClientID %>').clientWidth;


        if (DDE4._dropDownControl) {
            $common.removeHandlers(DDE4._dropDownControl, DDE4._dropDownControl$delegates);
        }
        if (DDE5._dropDownControl) {
            $common.removeHandlers(DDE5._dropDownControl, DDE5._dropDownControl$delegates);
        }



        DDE4._dropDownControl$delegates = {
            click: Function.createDelegate(DDE4, ShowMe),
            contextmenu: Function.createDelegate(DDE4, DDE4._dropDownControl_oncontextmenu)
        }
        DDE5._dropDownControl$delegates = {
            click: Function.createDelegate(DDE5, ShowMe),
            contextmenu: Function.createDelegate(DDE5, DDE5._dropDownControl_oncontextmenu)
        }


        $addHandlers(DDE4._dropDownControl, DDE4._dropDownControl$delegates);
        $addHandlers(DDE5._dropDownControl, DDE5._dropDownControl$delegates);
    }

    function ShowMe() {
        DDE4._wasClicked = true;
        DDE5._wasClicked = true;
    }

但我注意到 scipt 仅适用于“ucEducationInfo”用户控件。我尝试更改用户控件的行,我认为这是因为用户控件位于页面末尾。我不擅长 javascript。怎么了?

最佳答案

在我看来,实现自定义 ajax 控件应该是最好的决定。但是由于您没有使用 JavaScript 的经验,这对您来说是一项相当复杂的任务。尝试用下面的脚本替换用户控件中的 pageLoad 函数:

Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(function () {

    // code from pageLoad method here

    window.showControl = window.showControl || {};

    window.showControl["<%= this.ClientID %>"] = function () {
        DDE4._wasClicked = true;
        DDE5._wasClicked = true;
    };
});

下面是 ucEducationInfo 控件页面中 showControl 函数的用法示例:

showControl["<%= ucEducationInfo.ClientID %>"]();

关于javascript - 我如何在一个 aspx 页面上对每个用户控件使用 javascript pageLoad() 事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13325187/

相关文章:

.net - WPF:如何设置用户控件显示的对话框的所有者窗口?

javascript - 无论我在 Angular 项目中创建什么测试,都会因错误 : Illegal state: Could not load the summary for directive NotFoundComponent 而失败

javascript - 每秒生成随机背景颜色?

带有 YUI 的 ASP.NET MVC

.net - 允许在 URL 中使用星号

interop - 使用 VS.NET 构建 OCX?

javascript - 使用 javascript 捕获任何正在执行 http 请求的事件

JavaScript 源文件未在 IE8 弹出窗口中加载

asp.net - 更改用户名 ASP.net MVC 3 成员资格

WPF 用户控件加载两次