locked
postback is occuring when I click on radio button RRS feed

  • Question

  • User351619809 posted

    Hi All,

     I have the following code on my web page. Whenever I am clicking the radio button, postback is occuring. I am using Ajax. When I tried using triggers, it works, but when the deployed the code on server, the radio button stopped responding, if I remove the trigger then the radio button responds, but postback occurs. below is my code:

    <asp:updatePanel>   
     <ContentTemplate>
                <tr>
                    <td align="left">
                        Test1 Type:
                     
                       
                                <asp:RadioButtonList ID="rblTest1TypeId" RepeatDirection="horizontal" runat="server"
                                    AutoPostBack="true" >
                                </asp:RadioButtonList>
                           
                    </td>
                    <td style="width: 191px">
                        <asp:Button ID="btnClearTest1" runat="server" Text="Clear" CssClass="tab-button"
                            OnClick="btnClearTest1_Click" CausesValidation="false" />
                    </td>
                </tr>
             
            
                  <asp:UpdatePanel ID="updDisp" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true" >
                            <ContentTemplate>
                    <div runat="server" visible="false" id="divDisp" >--%>
                     
                          
                                <tr>
                                    <td align="left" colspan="6" style="padding: 0px 0 0px 0;">
                                        <asp:Panel ID="PanelTest1To" runat="server" Width="625px">
                                            <table border="0">
                                                <tr>
                                                    <td class="tab-panel-label" align="right" style="width: 150px;">
                                                        *Test1 To:
                                                    </td>
                                                    <td>
                                                        <asp:DropDownList ID="ddlTest1ToId" runat="server" AutoPostBack="True">
                                                        </asp:DropDownList>
                                                       <%-- <span style="font-size: 0.8em; color: #ff0000">Search above</span>--%>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="tab-panel-label" align="right" style="width: 150px;">
                                                        *Test5 Date:
                                                    </td>
                                                    <td class="tab-panel-field">
                                                        <asp:TextBox ID="txtTest5BeginDate" runat="server" Width="90px"></asp:TextBox>
                                                        <asp:ImageButton ID="ImgTest5BeginDate" runat="server" ImageUrl="~/images/calendar.gif" />
                                                        <span style="font-size: 0.8em; color: #ff0000">Format: mm/dd/yyyy</span>
                                                        <cc1:CalendarExtender ID="CldTest5BeginDate" runat="server" PopupButtonID="ImgTest5BeginDate"
                                                            TargetControlID="txtTest5BeginDate">
                                                        </cc1:CalendarExtender>
                                                    </td>
                                                </tr>
                                            </table>
                                        </asp:Panel>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="left" colspan="6" style="padding: 0px 0 0px 0;">
                                        <asp:Panel ID="PanelTest6" runat="server" Width="625px">
                                            <table border="0">
                                                <tr>
                                                    <td class="tab-panel-label" align="right" style="width: 100px;">
                                                        <asp:Label ID="lblTest6edDate" runat="server" Text="*Test6 Date:"></asp:Label>
                                                    </td>
                                                    <td class="tab-panel-field">
                                                        <asp:TextBox ID="txtTest6edDate" runat="server" Width="90px"></asp:TextBox>
                                                        <asp:ImageButton ID="ImgTest6edDate" runat="server" ImageUrl="~/images/calendar.gif" />
                                                        <span style="font-size: 0.8em; color: #ff0000">Format: mm/dd/yyyy</span>
                                                        <cc1:CalendarExtender ID="cldTest6edDate" runat="server" PopupButtonID="ImgTest6edDate"
                                                            TargetControlID="txtTest6edDate">
                                                        </cc1:CalendarExtender>
                                                    </td>
                                                </tr>
                                            </table>
                                        </asp:Panel>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="left" colspan="6" style="padding: 0px 0 0px 0;">
                                        <asp:Panel ID="PanelTest100" runat="server" Width="625px">
                                            <table border="0">
                                                <tr>
                                                    <td class="tab-panel-label" align="right" style="width: 200px;">
                                                        *Test100tal Num:
                                                    </td>
                                                    <td class="tab-panel-field">
                                                        <asp:TextBox ID="txtTest100No" runat="server" Width="156px"></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="tab-panel-label" align="right" style="width: 200px;">
                                                        <asp:Label ID="lblTest100BeginDate" runat="server" Text="*Test100tal Date:"></asp:Label>
                                                    </td>
                                                    <td class="tab-panel-field">
                                                        <asp:TextBox ID="txtTest100BeginDate" runat="server" Width="90px"></asp:TextBox>
                                                        <asp:ImageButton ID="imgTest100BeginDate" runat="server" ImageUrl="~/images/calendar.gif" />
                                                        <span style="font-size: 0.8em; color: #ff0000">Format: mm/dd/yyyy</span>
                                                        <cc1:CalendarExtender ID="CalendarExtender1" PopupButtonID="imgTest100BeginDate"
                                                            runat="server" TargetControlID="txtTest100BeginDate">
                                                        </cc1:CalendarExtender>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="tab-panel-label" align="right" style="width: 200px;">
                                                        <asp:Label ID="lblTest100Infor" runat="server" Text="Test100tal Information:"></asp:Label>
                                                    </td>
                                                    <td class="tab-panel-field">
                                                        <asp:TextBox ID="txtTest100Information" runat="server" Height="61px" TextMode="MultiLine"
                                                            Width="430px"></asp:TextBox>
                                                    </td>
                                                </tr>
                                            </table>
                                        </asp:Panel>
                                    </td>
                                </tr>
                            
                 
                       
                          </ContentTemplate>
                   
                            </asp:UpdatePanel>

    I have some code in the code behind that makes some panel visible and some panel visible=false

    Protected Sub rblTest1TypeId_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles rblTest1TypeId.SelectedIndexChanged
           
            If rblTest1TypeId.SelectedValue = 3 Then
                  do soemthing        
            ElseIf (rblTest1TypeId.SelectedValue = 2 Or rblTest1Id.SelectedValue = 4 Or rblTest1TypeId.SelectedValue = 5) Then
     do soemthing
                       Else
    do soemthing
                        End If
        End Sub

    any help will be greatly appreciated.

     

    Wednesday, May 11, 2016 9:25 PM

Answers

  • User61956409 posted

    Hi anjaliagarwal,

    <asp:updatePanel>

    UpdatePanel is missing attribute runat="server".

    Besides, you could set UpdateMode="Conditional" for UpdatePanel, then you could call .Update() method to update content after you change visible property of panel.

    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <asp:RadioButtonList ID="RadioButtonList1" RepeatDirection="horizontal" runat="server"
                AutoPostBack="true">
            </asp:RadioButtonList>
    
            <%-- your code--%>
        </ContentTemplate>
    </asp:UpdatePanel>
    
    UpdatePanel1.Update()

    Best Regards,

    Fei Han



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 12, 2016 3:18 AM
  • User351619809 posted

    This is the way I solved it:

    I put the following string in the page Load:

      ScriptManager1.RegisterAsyncPostBackControl(rblTest1TypeId)

    I tried UpdatePanel.Update(), it didn't work. Its still little bit slow, but no post back is occurring now.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 23, 2016 9:43 PM

All replies

  • User-1636183269 posted
    http://stackoverflow.com/questions/7547945/disable-postback-at-click-on-a-button
    Thursday, May 12, 2016 12:28 AM
  • User61956409 posted

    Hi anjaliagarwal,

    <asp:updatePanel>

    UpdatePanel is missing attribute runat="server".

    Besides, you could set UpdateMode="Conditional" for UpdatePanel, then you could call .Update() method to update content after you change visible property of panel.

    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <asp:RadioButtonList ID="RadioButtonList1" RepeatDirection="horizontal" runat="server"
                AutoPostBack="true">
            </asp:RadioButtonList>
    
            <%-- your code--%>
        </ContentTemplate>
    </asp:UpdatePanel>
    
    UpdatePanel1.Update()

    Best Regards,

    Fei Han



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 12, 2016 3:18 AM
  • User351619809 posted

    Please see the above code. I have runat="server" inb y updatePanel. It looks like this:

       <asp:UpdatePanel ID="updDisp" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true" >
                            <ContentTemplate>

    Friday, May 13, 2016 4:07 PM
  • User61956409 posted

    Hi anjaliagarwal,

    Please see the above code. I have runat="server" inb y updatePanel.

    Firstly, please check the code in your first post, you are using nested UpdatePanel, does the parent UpdatePanel control have runat="server" property?

    below is my code:

    <asp:updatePanel>   
     <ContentTemplate>
                <tr>
                    <td align="left">
                        Test1 Type:
                     
                       
                                <asp:RadioButtonList ID="rblTest1TypeId" RepeatDirection="horizontal" runat="server"
                                    AutoPostBack="true" >
                                </asp:RadioButtonList>
                           
                    </td>
                    <td style="width: 191px">
                        <asp:Button ID="btnClearTest1" runat="server" Text="Clear" CssClass="tab-button"
                            OnClick="btnClearTest1_Click" CausesValidation="false" />
                    </td>
                </tr>
             
            
                  <asp:UpdatePanel ID="updDisp" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true" >
                            <ContentTemplate>
                    <div runat="server" visible="false" id="divDisp" >--%>
                     
                          
                                <tr>
                                    <td align="left" colspan="6" style="padding: 0px 0 0px 0;">
                                        <asp:Panel ID="PanelTest1To" runat="server" Width="625px">
                                            <table border="0">
                                                <tr>
                                                    <td class="tab-panel-label" align="right" style="width: 150px;">
                                                        *Test1 To:
                                                    </td>
                                                    <td>
                                                        <asp:DropDownList ID="ddlTest1ToId" runat="server" AutoPostBack="True">
                                                        </asp:DropDownList>
                                                       <%-- <span style="font-size: 0.8em; color: #ff0000">Search above</span>--%>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="tab-panel-label" align="right" style="width: 150px;">
                                                        *Test5 Date:
                                                    </td>
                                                    <td class="tab-panel-field">
                                                        <asp:TextBox ID="txtTest5BeginDate" runat="server" Width="90px"></asp:TextBox>
                                                        <asp:ImageButton ID="ImgTest5BeginDate" runat="server" ImageUrl="~/images/calendar.gif" />
                                                        <span style="font-size: 0.8em; color: #ff0000">Format: mm/dd/yyyy</span>
                                                        <cc1:CalendarExtender ID="CldTest5BeginDate" runat="server" PopupButtonID="ImgTest5BeginDate"
                                                            TargetControlID="txtTest5BeginDate">
                                                        </cc1:CalendarExtender>
                                                    </td>
                                                </tr>
                                            </table>
                                        </asp:Panel>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="left" colspan="6" style="padding: 0px 0 0px 0;">
                                        <asp:Panel ID="PanelTest6" runat="server" Width="625px">
                                            <table border="0">
                                                <tr>
                                                    <td class="tab-panel-label" align="right" style="width: 100px;">
                                                        <asp:Label ID="lblTest6edDate" runat="server" Text="*Test6 Date:"></asp:Label>
                                                    </td>
                                                    <td class="tab-panel-field">
                                                        <asp:TextBox ID="txtTest6edDate" runat="server" Width="90px"></asp:TextBox>
                                                        <asp:ImageButton ID="ImgTest6edDate" runat="server" ImageUrl="~/images/calendar.gif" />
                                                        <span style="font-size: 0.8em; color: #ff0000">Format: mm/dd/yyyy</span>
                                                        <cc1:CalendarExtender ID="cldTest6edDate" runat="server" PopupButtonID="ImgTest6edDate"
                                                            TargetControlID="txtTest6edDate">
                                                        </cc1:CalendarExtender>
                                                    </td>
                                                </tr>
                                            </table>
                                        </asp:Panel>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="left" colspan="6" style="padding: 0px 0 0px 0;">
                                        <asp:Panel ID="PanelTest100" runat="server" Width="625px">
                                            <table border="0">
                                                <tr>
                                                    <td class="tab-panel-label" align="right" style="width: 200px;">
                                                        *Test100tal Num:
                                                    </td>
                                                    <td class="tab-panel-field">
                                                        <asp:TextBox ID="txtTest100No" runat="server" Width="156px"></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="tab-panel-label" align="right" style="width: 200px;">
                                                        <asp:Label ID="lblTest100BeginDate" runat="server" Text="*Test100tal Date:"></asp:Label>
                                                    </td>
                                                    <td class="tab-panel-field">
                                                        <asp:TextBox ID="txtTest100BeginDate" runat="server" Width="90px"></asp:TextBox>
                                                        <asp:ImageButton ID="imgTest100BeginDate" runat="server" ImageUrl="~/images/calendar.gif" />
                                                        <span style="font-size: 0.8em; color: #ff0000">Format: mm/dd/yyyy</span>
                                                        <cc1:CalendarExtender ID="CalendarExtender1" PopupButtonID="imgTest100BeginDate"
                                                            runat="server" TargetControlID="txtTest100BeginDate">
                                                        </cc1:CalendarExtender>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="tab-panel-label" align="right" style="width: 200px;">
                                                        <asp:Label ID="lblTest100Infor" runat="server" Text="Test100tal Information:"></asp:Label>
                                                    </td>
                                                    <td class="tab-panel-field">
                                                        <asp:TextBox ID="txtTest100Information" runat="server" Height="61px" TextMode="MultiLine"
                                                            Width="430px"></asp:TextBox>
                                                    </td>
                                                </tr>
                                            </table>
                                        </asp:Panel>
                                    </td>
                                </tr>
                            
                 
                       
                          </ContentTemplate>
                   
                            </asp:UpdatePanel>

    I have some code in the code behind that makes some panel visible and some panel visible=false

    Protected Sub rblTest1TypeId_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles rblTest1TypeId.SelectedIndexChanged
           
            If rblTest1TypeId.SelectedValue = 3 Then
                  do soemthing        
            ElseIf (rblTest1TypeId.SelectedValue = 2 Or rblTest1Id.SelectedValue = 4 Or rblTest1TypeId.SelectedValue = 5) Then
     do soemthing
                       Else
    do soemthing
                        End If
        End Sub

    Secondly, do you try to call .Update() method to update content?

    Best Regards,

    Fei Han

    Monday, May 16, 2016 8:54 AM
  • User351619809 posted

    This is the way I solved it:

    I put the following string in the page Load:

      ScriptManager1.RegisterAsyncPostBackControl(rblTest1TypeId)

    I tried UpdatePanel.Update(), it didn't work. Its still little bit slow, but no post back is occurring now.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 23, 2016 9:43 PM