locked
Controls Not Retaining Values after postback RRS feed

  • Question

  • User-247299154 posted

    This code works in my local environments and in other production applications.  However, this time when I click  CourseTitleSearchButton, any values entered by the user are not retained and the text fields are blank.

         <asp:Panel ID="CourseTitleSearchPanel" runat="server" Width="800px" CssClass="ModalWindow" style="display:none; text-align: center; margin:auto;">                 <span style="color: Blue">Search for your Course Title, if it isn't found then click 'Cancel' to manually type in the Course Title.</span>                 <table width="100%" cellspacing="0" border="0">                     <tr>                         <td style="width: 10%">                             <b>Course ID</b>                         </td>                         <td style="width: 10%">                             <asp:TextBox ID="CourseIdSearchTextBox" runat="server"/>                         </td>                         <td style="width: 10%">                             <b>Title</b>                         </td>                         <td style="width: 40%">                             <asp:TextBox ID="CourseTitleSearchTextBox" runat="server" Width="95%"/>                         </td>                         </td>                         <td style="width: 20%">                             <b>CSWF-Scoped Only</b>                         </td>                         <td style="width: 10%">                             <asp:CheckBox ID="CswfOnlyCheckBox" runat="server" Enabled="true" />                         </td>                     </tr>                     <tr>                         <td colspan="8" align="center">                             <asp:Button ID="CourseTitleSearchButton" runat="server" Text="Search" CssClass="bluebkg" OnClick="CourseTitleSearchButton_Click" UseSubmitBehavior="false" OnClientClick="CopyCourseTitleSearchValuesOutOfPopup();"/>                         </td>                     </tr>                 </table>                              <div    id="CourseTitleGridViewHeaderDiv" runat="server" visible="False"                         style="background-color:#CECECE; width: 90%; margin:auto;">                     <div>                         <div style="float: left">                             <asp:Button     ID="CourseTitlePrevLinkButton" runat="server" Text="<< Previous Page"                                             onclick="CourseTitlePrevLinkButton_Click" CssClass="LinkButton" UseSubmitBehavior="false"/>                         </div>                         <div style="float: right">                             <asp:Button     ID="CourseTitleNextLinkButton" runat="server" Text="Next Page >>"                                             onclick="CourseTitleNextLinkButton_Click" CssClass="LinkButton" UseSubmitBehavior="false"/>                         </div>                     </div>

                        <asp:DropDownList ID="CourseTitlePageDropDownList" runat="server" OnSelectedIndexChanged="CourseTitlePageDropDownList_SelectedIndexChanged" AutoPostBack="true">                         <asp:ListItem Text="1"/>                     </asp:DropDownList>

                        <br />                      <asp:Label ID="CourseTitleRecordCountLabel" runat="server"/>

                        <div style="text-align: left">                         <asp:GridView   ID="CourseTitleGridView" runat="server" DataKeyNames="course_id"                                         AutoGenerateColumns="False" Width="90%" GridLines="None"                                         EmptyDataText="No Course Titles Found">                             <AlternatingRowStyle BackColor="#EDEBC8" />                             <Columns>                                 <asp:TemplateField HeaderText="Course ID">                                     <ItemTemplate>                                         <div style="text-align:left">                                             <asp:Button ID="AddTitleButton" runat="server" CausesValidation="false" CommandArgument="<%# Container.DataItemIndex %>"                                                         Text='<%# Eval("cin")%>' OnClick="AddTitleButton_Click" CssClass="LinkButton" UseSubmitBehavior="false"/>                                         </div>                                     </ItemTemplate>                                 </asp:TemplateField>                                 <asp:TemplateField HeaderText="Course Title">                                     <ItemTemplate>                                         <asp:Label ID="CourseTitleLabel" runat="server" Text='<%# Eval("course_title")%>'></asp:Label>                                     </ItemTemplate>                                 </asp:TemplateField>

                                    <asp:BoundField DataField="delivery_method" HeaderText="Training Method" HeaderStyle-HorizontalAlign="Left" />                                 <asp:BoundField DataField="course_hours" HeaderText="Course Hours" HeaderStyle-HorizontalAlign="Left"  />                                 <asp:BoundField DataField="ceu" HeaderText="CEU" HeaderStyle-HorizontalAlign="Left"  />                             </Columns>                             <HeaderStyle BackColor="#CECECE" />                             <RowStyle BackColor="White" />                               </asp:GridView>                      </div>

                        <br />                     <asp:Label ID="CourseTitlePageLabel" runat="server"/>                 </div>

                    <br />                 <asp:Button     ID="CourseTitleCancelButton" runat="server" Text="Cancel"                                 onclick="CourseTitleCancelButton_Click" CssClass="bluebkg" UseSubmitBehavior="false"/>                            <br />             </asp:Panel>

                <asp:ModalPopupExtender ID="CourseTitlePopupExtender" runat="server"                                     DropShadow="True"                                     PopupControlID="CourseTitleSearchPanel"                                     BackgroundCssClass="modalBackground"                                     TargetControlID="CourseTargetControlIDFakeButton"/>

    Tuesday, January 20, 2015 2:06 PM

All replies

  • User1711366110 posted

    hi pattyk442,
     

    <asp:Button ID="CourseTitleSearchButton" runat="server" Text="Search" CssClass="bluebkg" OnClick="CourseTitleSearchButton_Click" UseSubmitBehavior="false" OnClientClick="CopyCourseTitleSearchValuesOutOfPopup();"/>

    As per your case, You can try with "return" in onClientClick like below :

    <asp:Button ID="CourseTitleSearchButton" runat="server" Text="Search" CssClass="bluebkg" 
    OnClick="CourseTitleSearchButton_Click" UseSubmitBehavior="false" 
    OnClientClick="return CopyCourseTitleSearchValuesOutOfPopup();"/>

    If the above code is not working ,then post the corresponding code of OnClientClick() & OnClick() events .       
    --
    with regards,
    Edwin

    Wednesday, January 21, 2015 2:01 AM
  • User-247299154 posted

    Thank you for your reply.
    The OnClientClick was added as a work around... in the original code I didn't have any client side script.  My issue is that when the postback happens, all of the textboxes are blank without any of the data entered by the user.

    Wednesday, January 21, 2015 9:15 AM
  • User-760709272 posted

    Post the relevant parts of your page_load, and\or check for any response.redirect statements you might be making

    Wednesday, January 21, 2015 9:43 AM
  • User-247299154 posted

       protected void Page_Load(object sender, EventArgs e)

        {

            ErrorLabel.Text = String.Empty;

            InfoLabel.Text = String.Empty;

            InfoLabel.Text = CourseTitleSearchTextBox.Text;

             if (!IsPostBack)

            {

                Session["idp"] = null;

                Session["user"] = null;

                 ViewState["TabIndex"] = "0";

                BindData();

            }

        }

    There are no redirect in the code... as soon as the page loads, the data is lost.  
    This code works perfectly in my local environment and in other production applications... could it be something in IIS why it isn't retaining.
    Also, it works if I take out the code:

    <asp:ModalPopupExtender ID="CourseTitlePopupExtender" runat="server" DropShadow="True"  PopupControlID="CourseTitleSearchPanel"  BackgroundCssClass="modalBackground" TargetControlID="CourseTargetControlIDFakeButton"/>


    Thanks for looking into this for me!!!
    I have racked my brain for 2 1/2 days.

    Wednesday, January 21, 2015 12:27 PM
  • User-760709272 posted

    Use something like Fiddler to look at the requests between the browser and your site when you submit the form.  Your code might not be doing a redirect but something in the server config might be doing it, like a rewrite rule or something.

    Wednesday, January 21, 2015 12:28 PM