简体   繁体   English

异步回发后更改控件的位置

[英]position of control is changed after asynchronous postback

i have a panel within an update panel in my page visible of panel is false by default and after asynchronous postback changes to true my problem is after postback location of panel change to top of page here is my code 我的页面上的更新面板中有一个面板,默认情况下该面板为false,并且异步回发更改为true后,我的问题是面板的回发位置更改为页面顶部后,这是我的代码

<asp:Label runat="server" ID="lbl_caption_upload" Text="caption" CssClass="label"></asp:Label>
<asp:TextBox runat="server" ID="txt_caption_upload" TextMode="MultiLine" CssClass="textbox"></asp:TextBox>
<asp:RadioButtonList runat="server" ID="radio_view_upload" OnSelectedIndexChanged="radio_view_upload_SelectedIndexChanged" AutoPostBack="True">
   <asp:ListItem text="custom"></asp:ListItem>
   <asp:ListItem text="public"></asp:ListItem></asp:RadioButtonList>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="radio_view_upload" />
                </Triggers>
                <ContentTemplate>
                    <asp:Panel runat="server" ID="placeholder_panel" Visible="false" CssClass="hide">
                        <tr>
                            <td>
                                <asp:Label runat="server" ID="lbl_genre_upload" Text="genre" CssClass="label"></asp:Label>
                            </td>
                            <td>
                                <asp:CheckBoxList runat="server" ID="check_genre_upload" DataTextField="Title" DataValueField="ID" RepeatColumns="7" RepeatDirection="Horizontal" DataSourceID="datasource_genre_upload"></asp:CheckBoxList>
                                <asp:LinqDataSource ID="datasource_genre_upload" runat="server" ContextTypeName="Video_Hosting.L2SDataContext" EntityTypeName="" Select="new (Title, ID)" TableName="Genres" OrderBy="ID">
                                </asp:LinqDataSource>
                            </td>
                        </tr>
                    </asp:Panel>
                </ContentTemplate>
            </asp:UpdatePanel>

and here is code for slectedindex change 这是slectedindex更改的代码

protected void radio_view_upload_SelectedIndexChanged(object sender, EventArgs e)
    { 
        if (radio_view_upload.SelectedIndex == 1)
        {
            placeholder_panel.Visible = true;
        } 
        else
        {
            placeholder_panel.Visible = false;
        }
    }

after postback location of panel change to before first label 面板的回发位置更改为第一个标签之前

thanks for all of your answers 谢谢你的回答

This line is the problem: 这行是问题所在:

if (radio_view_upload.SelectedIndex == 2)

Your radio_view_upload RadioButtonList only has 2 choices, so your if-statement will always go to the Else part. 您的radio_view_upload RadioButtonList仅具有2个选择,因此您的if语句将始终进入其他部分。 Only SelectedIndex 0 and 1 are available. 仅SelectedIndex 0和1可用。

In most programming languages the first item in an array, collection, list etc will have 0 as starting index. 在大多数编程语言中,数组,集合,列表等中的第一项将以0作为起始索引。

You could also use if (radio_view_upload.SelectedValue == "myValue") , but for this to work you have to add a value="myValue" to the ListItems. 您还可以使用if (radio_view_upload.SelectedValue == "myValue") ,但是要使其正常工作,您必须向ListItems添加value="myValue"

UPDATE 更新

Inside <ContentTemplate> you have a <tr> <td> and a </td> </tr> without matching <table> </table> tags. <ContentTemplate>您有一个<tr> <td></td> </tr>而没有匹配<table> </table>标记。 Maybe those tags are outside the UpdatePanel and not visible in your snippet. 也许这些标签在UpdatePanel之外,并且在您的代码段中不可见。 You should add/move those inside the UpdatePanel. 您应该在UpdatePanel中添加/移动这些内容。

UPDATE 2 更新2

    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <asp:FileUpload ID="FileUpload1" runat="server" />
    <br />
    <br />
    <asp:Label runat="server" ID="lbl_caption_upload" Text="caption" CssClass="label"></asp:Label>
    <br />
    <asp:TextBox runat="server" ID="txt_caption_upload" TextMode="MultiLine" CssClass="textbox"></asp:TextBox>
    <br />
    <asp:RadioButtonList runat="server" ID="radio_view_upload" OnSelectedIndexChanged="radio_view_upload_SelectedIndexChanged" AutoPostBack="True">
        <asp:ListItem Text="custom"></asp:ListItem>
        <asp:ListItem Text="public"></asp:ListItem>
    </asp:RadioButtonList>
    <br />

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="radio_view_upload" />
        </Triggers>
        <ContentTemplate>
            <asp:Panel runat="server" ID="placeholder_panel" Visible="true" CssClass="hide">
                <asp:Label runat="server" ID="lbl_genre_upload" Text="genre" CssClass="label"></asp:Label>
                <br />
                <asp:CheckBoxList runat="server" ID="check_genre_upload" DataTextField="Title" DataValueField="ID" RepeatColumns="7" RepeatDirection="Horizontal"></asp:CheckBoxList>
            </asp:Panel>
        </ContentTemplate>
    </asp:UpdatePanel>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM