引导模式不工作,因为它应该

本文关键字:因为 工作 模式 | 更新日期: 2023-09-27 18:12:53

我使用一个引导模式来保存和更新一些类型的事件。我的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();
    }

我的模式是完美的工作。一切都被加载,我可以编辑,但当我按下保存,这是在我的模态有问题。

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();
        }
    }

代码也是一个巨大的混乱,如果有人可以建议更好的方法与怪物工作,请让我知道。

引导模式不工作,因为它应该

您的保存按钮没有任何内容可以取消模式。我怀疑你的取消按钮的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服务器端函数将运行。