带有下拉列表和更新面板问题的modalpopupextender

时间:2013-12-28 05:52:18

标签: asp.net .net updatepanel modalpopupextender autopostback

我在弹出窗口中有asp:DetailsView(我使用modalpopupextender),dropdownlist内有detailsview的自动回复。 DetailView位于updatepanel内。但是,当我更改dropdownlist的值时,无论如何都会调用PageLoad函数,并且dropdown索引更改为0。

<asp:Button ID="FakeClickButton5" runat="server" Text="FakeButton" CssClass="hideButton" />

 <asp:Panel ID="PopupPanelDetail" runat="server" CssClass="modalPopup" >
    <asp:Panel ID="Panel6" runat="server"  >

    <asp:UpdatePanel ID="uptblTest" UpdateMode="Conditional"  runat="server">
    <ContentTemplate>
            <asp:DetailsView ID="DetailsViewMain" runat="server" AutoGenerateRows="false" 
                DataKeyNames="Id" DataSourceID="ObjectDataSourceDetailMain" Height="50px" 
                onitemcommand="DetailsViewMain_ItemCommand" 
                oniteminserted="DetailsViewMain_ItemInserted" 
                Width="250px"   >
                <Fields>
                    <asp:BoundField DataField="Id" HeaderText="Id" 
                        InsertVisible="False" ReadOnly="True" SortExpression="Id" 
                        Visible="False" />
                    <asp:BoundField DataField="name" HeaderText="name" 
                        SortExpression="name" />

                    <asp:TemplateField HeaderText="Type">
                        <ItemTemplate>
                            <asp:DropDownList ID="ddType" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddType_OnSelectedIndexChanged" onload="ddType_Load">
                            </asp:DropDownList>
                        </ItemTemplate>
                    </asp:TemplateField>

                    <asp:CommandField ShowEditButton="True" ShowInsertButton="True" 
                        Visible="False" />
                </Fields>
                <HeaderStyle CssClass="bold" HorizontalAlign="Center"></HeaderStyle>

            </asp:DetailsView>
    &nbsp;
            <asp:Panel ID="Panel7" runat="server">
                &nbsp;<asp:LinkButton ID="SaveDetailLinkButton" runat="server" CausesValidation="True"
                    onclick="SaveDetailLinkButton_Click" SkinID="blackButton" ValidationGroup="ServiceValidation">Save</asp:LinkButton>
                &nbsp;<asp:LinkButton ID="CancelDetailLinkButton3" runat="server" 
                    onclick="CancelDetailLinkButton3_Click" SkinID="blackButton">Cancel</asp:LinkButton>
            </asp:Panel>
        <asp:ObjectDataSource ID="ObjectDataSourceDetailMain" runat="server" 
            InsertMethod="InsertParam" 
            SelectMethod="GetParamByID" 
            UpdateMethod="UpdateParam" 
            TypeName="DatasorceMatch" 
            DataObjectTypeName="ParamCustom"
            OldValuesParameterFormatString="original_{0}" 
            oninserting="ObjectDataSourceDetailMain_Inserting" >
            <SelectParameters>
                <asp:ControlParameter ControlID="GridViewParams" Name="Id" 
                    PropertyName="SelectedDataKey.Value" Type="Int32" />
            </SelectParameters>
        </asp:ObjectDataSource>


        </ContentTemplate>
        </asp:UpdatePanel>


   </asp:Panel>
</asp:Panel>


<ajaxToolkit:ModalPopupExtender ID="ModalPopupExtenderDetails" runat="server" 
    PopupControlID="PopupPanelDetail"  TargetControlID="FakeClickButton2"    
    BackgroundCssClass="modalBackground" />

实际上,重新下载dropdownlist很奇怪,因为更新面板模式是有条件的,我不会在代码中更新它。

这是我的服务器代码:

protected void Page_Load(object sender, EventArgs e)
    {

    }

protected void DetailsViewMain_ItemCommand(object sender, DetailsViewCommandEventArgs e)
    {
        if (e.CommandName == "Cancel")
        {
            DetailsViewMain.Visible = false;
        }
    }
    protected void DetailsViewMain_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
    {
        GridViewParams.DataBind();
        DetailsViewMain.Visible = false;
    }
    protected void SaveDetailLinkButton_Click(object sender, EventArgs e)
    {
        Page.Validate();
        if (Page.IsValid)
        {
            GridViewParams.SelectedIndex = -1;
            if (DetailsViewMain.CurrentMode == DetailsViewMode.Edit)
            {
                DetailsViewMain.UpdateItem(true);

            }
            if (DetailsViewMain.CurrentMode == DetailsViewMode.Insert)
            {
                DetailsViewMain.InsertItem(true);

            }
            ModalPopupExtenderDetails.Hide();


            GridViewParams.DataBind();
        }
        else
        {
            ModalPopupExtenderDetails.Show();
        }
    }
    protected void CancelDetailLinkButton3_Click(object sender, EventArgs e)
    {
        ModalPopupExtenderDetails.Hide();
        GridViewParams.SelectedIndex = -1;
        GridViewParams.DataBind();
    }

    protected void ObjectDataSourceDetailMain_Inserting(object sender, ObjectDataSourceMethodEventArgs e)
    {
        //int selectedID_ofType = (int)ViewState[viewState_typeID];
        int selectedID_ofType = int.Parse(dropDownList_ddType.SelectedValue);
        ((ParamCustom)e.InputParameters[0]).typeID = selectedID_ofType;
    }

    protected void ddType_Load(object sender, EventArgs e)
    {
        dropDownList_ddType = (DropDownList)sender;
        if (DetailsViewMain.CurrentMode == DetailsViewMode.Insert)
        {
            ((DropDownList)sender).Items.Clear();
            ((DropDownList)sender).Items.Add(new ListItem(@"Choose", (0).ToString()));
            foreach (ParamType paramType in DBHelper.sharedInstance().getAllParamTypes())
            {
                ListItem listItem = new ListItem(paramType.name, paramType.id.ToString());
                ((DropDownList)sender).Items.Add(listItem);
            }
        }
    }

    protected void ddType_OnSelectedIndexChanged(object sender, EventArgs e)
    {
        //int selectedID_ofType = int.Parse(((DropDownList)sender).SelectedValue);
        //ViewState[viewState_typeID] = selectedID_ofType;
    }

我需要的是在没有页面重新加载或没有弹出消失的情况下更改下拉列表的值并保存此值。

0 个答案:

没有答案