在一个更新面板Modalpopup扩展,卫生组织控件的事件不触发 [英] Modalpopup extender in an update panel, whos controls events not firing

查看:200
本文介绍了在一个更新面板Modalpopup扩展,卫生组织控件的事件不触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是类似于在许多S.O.其他问题但他们都不适用于这种情况,也不会解决问题。问题是我有一个模式弹出控制到我的传递需要的基础上的其他控件。因此,当用户点击我的用户界面一键点击另一个按钮,他会得到不同的内容时,他能得到与模式一组的内容,那么。一切工作正常,直到我试图让事件从被添加到模式弹出内容开火。它不会完全准确地说我已经竭尽所能来解决这个问题,但我已经尝试了不少。我变得相信,这不是不能做,或者我有一些怎么设置不正确。

I know this is similar to many other questions on S.O. but none of them seem to apply to this situation, nor do they resolve the problem. The issue is I have one Modal Popup Control into which I pass other controls on an as needed basis. So when a user clicks one button on my UI he could get that modal with one set of content, then when clicking another button he would get different content. Everything was working fine until I tried to get events to fire from content that was added to the modal popup. It would not be entirely accurate to say I have tried everything to resolve this problem, but I have attempted quite a bit. I am becoming convinced that this either can not be done, or I have some how set it up incorrectly.

这是这个code为更新面板

This is this code for the update panel

<input id="dummy" type="button" style="display: none" runat="server" />
<asp:ModalPopupExtender CancelControlID="Close" runat="server" ID="mpeThePopup" TargetControlID="dummy" PopupControlID="pnlModalPopUpPanel" BackgroundCssClass="modalBackground" PopupDragHandleControlID="Title" />
<asp:Panel ID="pnlModalPopUpPanel" runat="server" CssClass="modalPopup" Width="400px" Height="600px">
    <asp:UpdatePanel ID="udpInnerUpdatePanel" runat="Server">
        <ContentTemplate>
            <table id="ContentTableTag" runat="server" cellpadding="0" cellspacing="0" style="width: 100%;
                height: 100%;">
                <tr>
                    <td id="Title" runat="server" style="background-color: rgb(79,82,90); text-align: left;
                        height: 28px; width: 90%; color: White;" nowrap="nowrap">
                        <h4 style="margin: 0px 0px 0px 5px;">
                            <asp:Label ID="LblSectionTitle" runat="server" Text="Modal"></asp:Label>
                        </h4>
                    </td>
                    <td id="Close" runat="server" style="background-color: rgb(79,82,90); text-align: right;
                        height: 28px; width: 10%" nowrap="nowrap">
                        <asp:ImageButton ID="ibClose" runat="server" Style="margin-right: 5px;" ImageUrl="~/WLImages/MLS/button_close.png"
                            ToolTip="Close" />
                    </td>
                </tr>
                <tr>
                    <td id="MainContentHolder" colspan="2" align="left" style="top: 0px; bottom: 100%;
                        vertical-align: top; width: 100%; height: 100%" />
                </tr>
            </table>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Panel>

这是code表示,我增加了模式弹出用户控制,在其背景是两个事件触发器,一个用于当日历改变其日期,以及一个用于当该复选框的项目被选中。

This is the code for the user control that I am adding to the modal popup, in its background are two event triggers, one for when the calendar changes its date, and one for when on of the check box items are checked.

<table id="mainContent" runat="server" visible="false" width="350" height="300">
    <tr>
        <td>
            <asp:label ForeColor="White" runat="server" Text="Exam Date:" />
        </td>
        <td>
            <asp:TextBox ID="txtDate" runat="server" Width="127" ForeColor="Black" 
                readonly="true" ontextchanged="txtDate_TextChanged"/>
            <asp:CalendarExtender ID="CalendarExtender" runat="server" 
                PopupButtonID="ibtnCalendar" OnClientDateSelectionChanged="checkDate" 
                TargetControlID="txtDate" onload="LoadCalendar" />
        </td>
        <td>
            <asp:ImageButton ID="ibtnCalendar" ImageUrl="../imgs/btn_calendar.png" Width="20px" runat="server" />
        </td>
    </tr>
    <tr>
        <td style="vertical-align: top; padding-top:5px">
            <asp:label ForeColor="White" runat="server" Text="Study Days:" />
        </td>
        <td colspan="2" style="vertical-align: top; padding-top:5px">
            <asp:CheckBoxList ID="WeekCheckBox" runat="server" ForeColor="White" 
                onselectedindexchanged="WeekCheckBox_SelectedIndexChanged">
                <asp:ListItem Text="Monday" Value="1" />
                <asp:ListItem Text="Tuesday" Value="2" />
                <asp:ListItem Text="Wednesday" Value="3" />
                <asp:ListItem Text="Thursday" Value="4" />
                <asp:ListItem Text="Friday" Value="5" />
                <asp:ListItem Text="Saturday" Value="6" />
                <asp:ListItem Text="Sunday" Value="7" />
            </asp:CheckBoxList>
        </td>
    </tr>
    <tr>
        <td>
            <asp:label ForeColor="White" runat="server" Text="Study hours per day:" />
        </td>
        <td colspan="2">
            <asp:TextBox ForeColor="Black" ID="tbStudyHours" runat="server" Width="127px" ReadOnly="true" />
        </td>
    </tr>
</table>

最后,这是我贴上控制模态。

Finally this is how I attach the control to the modal.

private void GenerateCalendarPopup(ExamDateSelector eds)
    {
        pnlModalPopUpPanel.BackColor = GUI.Instance.GUIColorElement(GUIElements.color_main);
        LblSectionTitle.Text = "Exam Date";
        pnlModalPopUpPanel.Height = eds.ControlHeight + 40;
        pnlModalPopUpPanel.Width = eds.ControlWidth + 25;
        eds.ShowControl = true;
        MainContentHolder.Controls.Add(eds);
    }

感谢您的任何帮助。

推荐答案

虽然这未必是正确的方式通过试图复制我们的Windows产品的流动性和风格来处理我已经为自己创建的情况网上,我没有找到一个方法来解决不从时$ p $在模式弹出psented这种控制触发事件的问题;尽管在一种迂回的方式。
首先,我写了一个JavaScript函数,该函数的大部分,我会放在控件的事件数学的;本质上,它计算的学习时间从现在的具体日期要考虑到用户已选定为学习日一周中的几天之间留有量。然后我通过,我通过使用一个WebMethod的保存到数据库中的信息。

Though this may not be the "right" way to deal with the situation I have created for myself by attempting to copy the flow and style of our windows product for the web, I did find a way to resolve the issue of events not firing from this control when presented in a modal popup; though in a roundabout way. First I wrote a function in javascript, the function does the bulk of the math that I would have put in the events of the control; essentially it calculates the amount of study time left between now and a specific date taking into account the days of the week the user has selected as study days. I then pass the information that I am saving to the database through the use of a webmethod.

function calculateStudyTime() {
    //do some math
    …
    PageMethods.SaveModalExamDateChangesToDB(datesString, selectedDate);
}

我附上脚本每次我想在我的codebehind触发计算的控件。在我来说,我要重新计算研究的时候复选框有史以来逐一重新presenting的一周中的一天被触发。所以我重视剧本到列表项的控制。我就是这么做的,因为ListItem控件实际上并没有经过设计师的onclick属性访问,但可以添加这样的。

I attach the script to each of the controls that I want to trigger a calculation in my codebehind. In my case I want to recalculate the study time when ever one of the checkboxes representing a day of the week is toggled. So I attached the script to the ListItem controls. I did it this way because a ListItem control does not actually have an onclick attribute accessible through the designer, but one can be added this way.

protected void LoadCalendar(object sender, EventArgs e)
{

   …
   foreach (ListItem item in WeekCheckBox.Items)
   {
      item.Attributes.Add("onclick", "calculateStudyTime()");
   }
      …
}

最后,在从其中所有模式弹出的正在被称为我创建静态参照该基页,并可以从JavaScript文件称为装饰功能基页。需要静态参照本身,所以我可以访问基页面的部件(在这种情况下,我的上下文中)从静态web方法。

Finally in the base page from which all of the modal popup’s are being called I create a static reference to that base page, and the adorned function to be called from the javascript file. The static reference to itself is needed so I can access the members of the base page (in this case my context) from the static web method.

Static Dashboard thisPage;
protected void Page_Load(object sender, EventArgs e)
{
   …
   thisref = this;
   …
}

[WebMethod]
[ScriptMethod]
public static void SaveModalExamDateChangesToDB(string days, string date)
{
   thisPage.UserSession.UserCourse.ExamDate = DateTime.Parse(date);
   thisPage.UserSession.UserCourse.StudyDays = days;
   thisPage.UserSession.UserCourse.Save();
}

就像我说的是不理想,但它的工作原理。

Like I said it is not ideal, but it works.

这篇关于在一个更新面板Modalpopup扩展,卫生组织控件的事件不触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆