Title: position of control is changed after asynchronous postback
Tags: c#;asp.net;asynchronous;updatepanel
Question: 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
<asp:Label runat="server" ID="lbl_caption_upload" Text="caption" CssClass="label"&gt;</asp:Label&gt;
<asp:TextBox runat="server" ID="txt_caption_upload" TextMode="MultiLine" CssClass="textbox"&gt;</asp:TextBox&gt;
<asp:RadioButtonList runat="server" ID="radio_view_upload" OnSelectedIndexChanged="radio_view_upload_SelectedIndexChanged" AutoPostBack="True"&gt;
<asp:ListItem text="custom"&gt;</asp:ListItem&gt;
<asp:ListItem text="public"&gt;</asp:ListItem&gt;</asp:RadioButtonList&gt;
<asp:ScriptManager ID="ScriptManager1" runat="server"&gt;</asp:ScriptManager&gt;
<asp:UpdatePanel ID="UpdatePanel1" runat="server"&gt;
<Triggers&gt;
<asp:AsyncPostBackTrigger ControlID="radio_view_upload" /&gt;
</Triggers&gt;
<ContentTemplate&gt;
<asp:Panel runat="server" ID="placeholder_panel" Visible="false" CssClass="hide"&gt;
<tr&gt;
<td&gt;
<asp:Label runat="server" ID="lbl_genre_upload" Text="genre" CssClass="label"&gt;</asp:Label&gt;
</td&gt;
<td&gt;
<asp:CheckBoxList runat="server" ID="check_genre_upload" DataTextField="Title" DataValueField="ID" RepeatColumns="7" RepeatDirection="Horizontal" DataSourceID="datasource_genre_upload"&gt;</asp:CheckBoxList&gt;
<asp:LinqDataSource ID="datasource_genre_upload" runat="server" ContextTypeName="Video_Hosting.L2SDataContext" EntityTypeName="" Select="new (Title, ID)" TableName="Genres" OrderBy="ID"&gt;
</asp:LinqDataSource&gt;
</td&gt;
</tr&gt;
</asp:Panel&gt;
</ContentTemplate&gt;
</asp:UpdatePanel&gt;
and here is code for slectedindex change
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

Here is the accepted answer: 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. Only SelectedIndex 0 and 1 are available.
In most programming languages the first item in an array, collection, list etc will have 0 as starting index.
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.
UPDATE
Inside <ContentTemplate&gt; you have a <tr&gt; <td&gt; and a </td&gt; </tr&gt; without matching <table&gt; </table&gt; tags. Maybe those tags are outside the UpdatePanel and not visible in your snippet. You should add/move those inside the UpdatePanel.
UPDATE 2
<asp:ScriptManager ID="ScriptManager1" runat="server"&gt;</asp:ScriptManager&gt;
<asp:FileUpload ID="FileUpload1" runat="server" /&gt;
<br /&gt;
<br /&gt;
<asp:Label runat="server" ID="lbl_caption_upload" Text="caption" CssClass="label"&gt;</asp:Label&gt;
<br /&gt;
<asp:TextBox runat="server" ID="txt_caption_upload" TextMode="MultiLine" CssClass="textbox"&gt;</asp:TextBox&gt;
<br /&gt;
<asp:RadioButtonList runat="server" ID="radio_view_upload" OnSelectedIndexChanged="radio_view_upload_SelectedIndexChanged" AutoPostBack="True"&gt;
<asp:ListItem Text="custom"&gt;</asp:ListItem&gt;
<asp:ListItem Text="public"&gt;</asp:ListItem&gt;
</asp:RadioButtonList&gt;
<br /&gt;
<asp:UpdatePanel ID="UpdatePanel1" runat="server"&gt;
<Triggers&gt;
<asp:AsyncPostBackTrigger ControlID="radio_view_upload" /&gt;
</Triggers&gt;
<ContentTemplate&gt;
<asp:Panel runat="server" ID="placeholder_panel" Visible="true" CssClass="hide"&gt;
<asp:Label runat="server" ID="lbl_genre_upload" Text="genre" CssClass="label"&gt;</asp:Label&gt;
<br /&gt;
<asp:CheckBoxList runat="server" ID="check_genre_upload" DataTextField="Title" DataValueField="ID" RepeatColumns="7" RepeatDirection="Horizontal"&gt;</asp:CheckBoxList&gt;
</asp:Panel&gt;
</ContentTemplate&gt;
</asp:UpdatePanel&gt;
Comment for this answer: I tested your code and it all works as it should with those 2 fixes I mentioned. The only thing i cannot test is the content of `datasource_genre_upload`. Maybe there is something in there that causes the problem. Could you post (part of) the content of datasource_genre_upload?
Comment for this answer: And you cannot prevent the FileUpload from losing the file after a full postback. You have to store the file server side if you want to keep it. See http://stackoverflow.com/a/18656681/5836671
Comment for this answer: I sort know what you mean. But that is possible by using your snippet. I've edited it a litte. But the filename is preserved when `radio_view_upload` is changed.
Comment for this answer: Good to hear. Happy programming!
Comment for this answer: Thanks for your answer but this is not my problem.  .. My problem is changing location of panel ... Visiblity of panel is changed to true but location of it change to top of page
Comment for this answer: Thanks again i remove those tag but same problem ... When full postback occured location is true but in asynchronous postback location is changed ... I have a fileupload control that after full postback loose its file ... Only way to keep file is asynchronous postback... Session is not good idea for keep file
Comment for this answer: Yeah datasource contain genre of movies like comedy etc
Comment for this answer: No no no i save uploaded file after botton upload click ... But before save file i want to have some details about file like genre etc ... This require postback that cause loosing value of fileupload
Comment for this answer: Solved i used table tag in my page i change all table, tr and td tags to asp: table tags and problem solved


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2016:00:08/11/16', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<c#><asp.net><asynchronous><updatepanel>', 'Title': 'position of control is changed after asynchronous postback', 'ViewCount': 242, 'id': 38904888, 'user_AboutMe': None, 'user_AccountId': 8922773.0, 'user_DisplayName': 'user6658617', 'user_Reputation': 3.0, 'user_Views': 3.0, 'user_id': 6658617.0}}