每次都会出现模态调用页面加载问题

时间:2016-04-09 19:38:49

标签: javascript c# asp.net twitter-bootstrap modal-dialog

所以我的这个面板上有一堆按钮/项目。每个按钮都负责启动模态,并设置设定值。

我的问题是,每当我按下其中一个按钮时,模式会弹出正确的内容,但主页面会弹出Page_Load,所有折叠面板都会折叠,内容会刷新并从数据库中重新获取数据。

我认为它与我的模态脚本有关,但我只是不擅长理解javascript xD尝试在页面加载中强制使用if(!IsPostback)等但没有成功。

我的模态观点:

<div class="modal " id="modal123" > <div class="modal-dialog modal-lg"> <div class="modal-content"> <div class="modal-header"> <h4 class="modal-title" id="myModalLabel"> <asp:Label ID="title" runat="server" Text="Tittel"></asp:Label> </h4> </div> <div class="modal-body"> <asp:Label ID="article" runat="server" Text="Info"></asp:Label> </div> <div class="modal-footer"> <button type="button" class="btn btn-danger" data-dismiss="modal"> close</button> </div> </div> </div> </div>

我的模态脚本:

    <script type="text/javascript">
    function openModal() {
        $("#modal-content").load("pages/modals/density_control.php", function () {
            $("#element").focus();
        });
        $('#modal123').modal('show');


    };
</script>

按下折叠面板上按钮的值:

        public void FillFaseTable(Table t, int PID, int lifelineID)
    {

        List<Module> listMod = new List<Module>();
        listMod = DbDataAccessLayer.GetModuleByPhase(PID, lifelineID);
        foreach (var Module in listMod)
        {


            TableRow tRow = new TableRow();
            t.Rows.Add(tRow);
            TableCell tCell = new TableCell();
            LifelineButton btn = new LifelineButton();
            btn.MID = Module.mid;
            btn.moduleID = Module.moduleID;
            btn.title = Module.title;
            btn.Text = Module.title;
            btn.article = Module.article;
            btn.CssClass = "btn btn-primary btn-block btnConfig";
            btn.Attributes["data-toggle"] = "modal";
            btn.Attributes["data-target"] = "#modal123";
            btn.Click += new EventHandler(this.GreetingBtn_Click);
            tCell.Controls.Add(btn);
            tRow.Cells.Add(tCell);
        }
    }

Buttonclick:

        void GreetingBtn_Click(Object sender, EventArgs e)
    {
        LifelineButton clicked = (LifelineButton)sender;
        title.Text = clicked.title;
        article.Text = clicked.article;
        ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModal();", true);
    }

0 个答案:

没有答案