Bootstrap模式不能正常工作

时间:2015-09-15 13:21:43

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

我正在使用bootstrap模式来保存和更新某种事件。我的asp代码是:

<asp:UpdatePanel ID="upModal" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional">
    <ContentTemplate>
        <div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" id="myModal" aria-labelledby="myLargeModalLabel">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="gridSystemModalLabel">Add event:</h4>
                    </div>
                    <div class="modal-body">
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-md-3">
                                    <div class="row">
                                        <div class="col-md-12">
                                            <h4>Date:</h4>
                                        </div>
                                        <div class="col-md-12">
                                            <asp:TextBox ID="TextBoxDate" runat="server" Width="100" CssClass="rbl"></asp:TextBox>
                                            <asp:ImageButton ID="ImageButton2" ImageUrl="~/calendar.png" CssClass="rbl" runat="server" Height="20" Width="20" />
                                            <ajaxToolkit:CalendarExtender ID="CalendarExtender2" TargetControlID="TextBoxDate" runat="server" PopupButtonID="ImageButton2" Format="dd/MM/yyyy" />
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-3">
                                    <div class="row">
                                        <div class="col-md-12">
                                            <h4>List</h4>
                                        </div>
                                        <div class="col-md-12">
                                            <asp:ListBox ID="ListBoxEgk" runat="server"></asp:ListBox>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-3">
                                    <div class="row">
                                        <div class="col-md-12">
                                            <h4>info from:</h4>
                                        </div>
                                        <div class="col-md-12">
                                            <asp:TextBox ID="name" runat="server"></asp:TextBox>
                                        </div>
                                        <div class="col-md-12">
                                            <h4>to:</h4>
                                        </div>
                                        <div class="col-md-12">
                                            <asp:ListBox ID="ListBoxEpik" runat="server"></asp:ListBox>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-3">
                                    <div class="row">
                                        <div class="col-md-12">
                                            <h4>Kind of event:</h4>
                                        </div>
                                        <div class="col-md-12">
                                            <asp:ListBox ID="ListBoxEidosSum" runat="server"></asp:ListBox>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-md-5">
                                    <div class="col-md-12">
                                        <h4>Event desc:</h4>
                                    </div>
                                    <div class="col-md-12">
                                        <asp:TextBox ID="TextBoxSumvan" runat="server" Height="210px" MaxLength="500" Rows="12" Width="380px" TextMode="MultiLine"></asp:TextBox>
                                    </div>
                                </div>
                                <div class="col-md-5">
                                    <div class="col-md-12">
                                        <h4>Actions:</h4>
                                    </div>
                                    <div class="col-md-12">
                                        <asp:TextBox ID="TextBoxE" runat="server" Height="210px" MaxLength="500" Rows="12" Width="380px" TextMode="MultiLine"></asp:TextBox>
                                    </div>
                                </div>
                                <div class="col-md-2">
                                    <div class="col-md-12">
                                        <h4>Given to:</h4>
                                    </div>
                                    <div class="col-md-12">
                                        <asp:ListBox ID="ListBoxUsers" runat="server"></asp:ListBox>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <asp:Button ID="cancelBtn" CssClass="btn btn-default" runat="server" data-dismiss="modal" Text="Ακύρωση" OnClick="cancelBtn_Click" />
                        <asp:Button ID="saveBtn" runat="server" Text="Αποθήκευση" CssClass="btn btn-primary" OnClick="Btn_save_Click" />
                    </div>
                </div>

            </div>
        </div>
    </ContentTemplate>
</asp:UpdatePanel>

我通过以下方式“召唤”这个模态:

img ID="addEvent" src="/very-basic-plus-icon.png" data-toggle="modal" data-target=".bs-example-modal-lg" Height="20" Width="20" />

它有效。模态出现了,在我使用<asp:Updatepanel>之前,它工作正常,但我希望能够从网格中选择事件并显示此模态,如果必须则更新它们等。图像按钮下方是调用从后面开始的方法

<asp:ImageButton ID="imgEdit" ImageUrl="~/edit.png" runat="server" OnClick="imgEdit_Click" /> 

从后面跑的是:

static Boolean indexY = false;
    static newEvent event4Update = new newEvent();
    protected void imgEdit_Click(object sender, ImageClickEventArgs e)
    {
        GridViewRow gvRow = (GridViewRow)(sender as Control).Parent.Parent;
        int index = gvRow.RowIndex;
        var item = searchEvents.ElementAt(index);

        CMMS_IServiceClient client = new CMMS_IServiceClient();
        event4Update = client.returnRowForUpdate(item.RowId);            
        client.Close();

        TextBoxDate.Text = Convert.ToString(event4Update.ImerominiaSumvantos);
        name.Text = event4Update.Name;
        ListBoxEgk.SelectedValue = event4Update.From;
        ListBoxEpik.SelectedValue = event4Update.TroposEpikoinwnias;
        UserListBox.SelectedValue = event4Update.AssignmentTo;
        TextBoxSumvan.Text = event4Update.Sumvan;
        ListBoxEidosSum.SelectedValue = event4Update.TypeOfEvent;
        TextBoxEnergeies.Text = event4Update.Actions;
        ListBoxUsers.SelectedValue = event4Update.To;

        indexY = true;
        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "myModal", "$('#myModal').modal();", true);
        upModal.Update();

    }

Atm我的模态很完美。一切都已加载,我可以编辑但是当我按下保存时,我的模态内有问题。

protected void Btn_save_Click(object sender, EventArgs e)
    {
        CMMS_IServiceClient client = new CMMS_IServiceClient();
        if (ListBoxEgk.SelectedValue.ToString() == "" ||
            ListBoxEpik.SelectedValue.ToString() == "" ||
            TextBoxSumvan.Text == "" ||
            ListBoxEidosSum.SelectedValue.ToString() == "")
        {                
            Page.ClientScript.RegisterStartupScript(GetType(), "Scripts", "<script>alert('Some field is empty.');</script>");
        }
        else
        {
            if (indexY == true)
            {
                IFormatProvider culture = new System.Globalization.CultureInfo("fr-FR", true);
                newEvent updateEvent = new newEvent();
                updateEvent.RowId = event4Update.RowId;
                updateEvent.ImerominiaSumvantos = DateTime.Parse(TextBoxDate.Text, culture, System.Globalization.DateTimeStyles.AssumeLocal);
                updateEvent.Name = name.Text;
                updateEvent.From = ListBoxEgk.SelectedValue.ToString();
                updateEvent.TroposEpikoinwnias = ListBoxEpik.SelectedValue.ToString();
                updateEvent.To = UserListBox.SelectedValue.ToString();
                updateEvent.Sumvan = TextBoxSumvan.Text;
                updateEvent.TypeOfEvent = ListBoxEidosSum.SelectedValue.ToString();
                updateEvent.Actions = TextBoxEnergeies.Text;
                updateEvent.AssignmentTo = ListBoxUsers.SelectedValue.ToString();
                updateEvent.EventState = (TextBoxEnergeies.Text != "") ? true : false;
                client.updateRow(updateEvent);
                indexY = false;
                event4Update = null;
            }
            else
            {
                IFormatProvider culture = new System.Globalization.CultureInfo("fr-FR", true);
                newEvent addEvent = new newEvent();
                addEvent.ImerominiaSumvantos = DateTime.Parse(TextBoxDate.Text, culture, System.Globalization.DateTimeStyles.AssumeLocal);
                addEvent.Name = name.Text;
                addEvent.From = ListBoxEgk.SelectedValue.ToString();
                addEvent.TroposEpikoinwnias = ListBoxEpik.SelectedValue.ToString();
                addEvent.To = UserListBox.SelectedValue.ToString();
                addEvent.Sumvan = TextBoxSumvan.Text;
                addEvent.TypeOfEvent = ListBoxEidosSum.SelectedValue.ToString();
                addEvent.Actions = TextBoxEnergeies.Text;
                addEvent.AssignmentTo = ListBoxUsers.SelectedValue.ToString();
                addEvent.EventState = (TextBoxEnergeies.Text != "") ? true : false;
                client.write(addEvent);
            }

            client.Close();

            ListBoxEgk.ClearSelection();
            ListBoxEidosSum.ClearSelection();
            ListBoxEpik.ClearSelection();
            name.Text = "";
            TextBoxEnergeies.Text = "";
            TextBoxSumvan.Text = "";
            TextBoxDate.Text = "";
            ListBoxUsers.ClearSelection();
            searchBtn_Click(sender, e); 

            //ScriptManager.RegisterStartupScript(Page, Page.GetType(), "myModal", "$('#myModal').modal();", true);
            //upModal.Update();

        }
    }

代码也是一个巨大的混乱,如果有人可以建议更好的方式来处理我制作的怪物,请告诉我。

1 个答案:

答案 0 :(得分:0)

您的保存按钮无法解除模态。我怀疑你的取消按钮的data-dismiss属性可能与回发机制相互影响。

试试这个:

<asp:Button ID="cancelBtn" CssClass="btn btn-default" runat="server" Text="Ακύρωση" OnClientClick="dismissModal();" OnClick="cancelBtn_Click" />

<asp:Button ID="saveBtn" runat="server" Text="Αποθήκευση" CssClass="btn btn-primary" OnClick="Btn_save_Click" OnClientClick="dismissModal();" />

function dismissModal() {
    $('#myModal').modal('hide');
}

将运行OnClientClick客户端方法,然后将发生回发,并且您的OnClick服务器端功能将运行。