UpdatePanel and document.ready() Sys.Application.add_load not adding handler

限于喜欢 提交于 2019-12-25 03:08:40

问题


I want my div to visible on the basis of HiddenFiled value. So I did the following:

ASPX

<asp:UpdatePanel ID="up" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
    <script type="text/javascript">
        Sys.Application.add_load(BindEvents);
     </script>
        <div id="addPopUp" runat="server" style="padding: 30px; height: auto; width: 450px;
            overflow: hidden; display: none; background-color: White; border: 1px solid black;">
            <table width="500px;">
                <tr>
                    <td valign="top" align="left" style="width: 27%;">
                        <input type="hidden" runat="server" id="hfLevel" />
                        <input type="hidden" runat="server" id="hfLevel1Id" />
                        <input type="hidden" runat="server" id="hfLevel2Id" />
                        <input type="hidden" runat="server" id="hfLevel3Id" />
                    </td>
                    <td style="width: 80%;">
                    </td>
                </tr>
                <tr>
                    <td style="width: 20%;" align="left" class="topics">
                        &nbsp;
                    </td>
                    <td style="width: 80%;">
                        <asp:RadioButton ID="radAdd" runat="server" AutoPostBack="true" GroupName="ModeAddEdit"
                            Text="Add Link" Checked="true" OnCheckedChanged="radAdd_CheckedChanged" />
                        <asp:RadioButton ID="radEdit" runat="server" AutoPostBack="true" GroupName="ModeAddEdit"
                            Text="Edit Link" OnCheckedChanged="radEdit_CheckedChanged" />
                    </td>
                </tr>
                <tr>
                    <td style="width: 20%;" align="left" class="topics">
                        <strong>Link Name :</strong>
                    </td>
                    <td style="width: 80%;">
                        <asp:TextBox ID="txtLinkName" CssClass="txtbox" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td style="width: 20%;" class="topics">
                        <strong>Url :</strong>
                    </td>
                    <td style="width: 80%;">
                        <asp:TextBox ID="txtUrl" CssClass="txtbox" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td style="width: 20%;" class="topics">
                        <strong>Position :</strong>
                    </td>
                    <td style="width: 80%;">
                        <asp:TextBox ID="txtPosition" CssClass="txtbox" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td style="width: 20%;" class="topics">
                        <strong>Show on same page :</strong>
                    </td>
                    <td style="width: 80%;">
                        <asp:CheckBox ID="chkSamePage" runat="server" Checked="true" />
                    </td>
                </tr>
                <tr>
                    <td>
                        &nbsp;
                    </td>
                    <td class="topics" align="left">
                        <asp:Button ID="btnSave" runat="server" Text="Save" CssClass="sfCustomButton" OnClick="btnSave_Click" />
                        &nbsp;&nbsp;
                        <asp:Button ID="btnHide" runat="server" Text="Hide Link" CssClass="sfCustomButton" />
                        &nbsp;&nbsp;
                        <input type="button" id="btnCancel" value="Cancel" class="sfCustomButton" onclick="hide()" />
                    </td>
                </tr>
            </table>
        </div>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="radAdd" />
        <asp:AsyncPostBackTrigger ControlID="radEdit" />
        <asp:PostBackTrigger ControlID="btnSave" />
        <asp:PostBackTrigger ControlID="btnHide" />
    </Triggers>
</asp:UpdatePanel>

and CODE BEHIND

 protected void radAdd_CheckedChanged(Object sender, EventArgs e)
        {
            hfShow.Value = "1";
        }

        protected void radEdit_CheckedChanged(Object sender,  EventArgs e)
        {
            hfShow.Value = "1";
        }

JAVASCRIPT

  function BindEvents() {
        $(document).ready(function () {
            var hf = document.getElementById("hfShow"); alert(hf.value);
            if (hf.value == "1") {
                Popup.showModal('addPopUp', null, null, { 'screenColor': '#cccccc', 'screenOpacity': .6 });
            }
        });
    }

I am helpless to find the issue behind why alert(hf.value); is not working, I guess Sys.Application.add_load(BindEvents); is not working, Anyone knows why its not working ? Thanks.

来源:https://stackoverflow.com/questions/22190374/updatepanel-and-document-ready-sys-application-add-load-not-adding-handler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!