This is a migrated thread and some comments may be shown as answers.

Clicking on a button doesn't appear to cause a postback?

4 Answers 110 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Rem
Top achievements
Rank 1
Rem asked on 16 Feb 2010, 11:18 PM
I have been having a problem on my page where clicking on the button doesn't appear to cause a post-back (although stepping through the code shows that it is going through the lines of code in the code behind page.

I created a new simple project and have been able to reproduce the issue:

Default.aspx:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %> 
 
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="rad" %> 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml">  
<head runat="server">  
    <title></title>  
</head> 
<body> 
    <form id="form1" runat="server">  
        <div> 
            <asp:Panel class="clientheading" ID="Panel1" runat="server" BorderWidth="0px" Visible="False">  
                <asp:Label ID="header1" runat="server" >Test</asp:Label>&nbsp;  
            </asp:Panel> 
              
              
            <rad:RadScriptManager runat="server" ID="RadScriptManager1" /> 
              
            <rad:RadAjaxManager ID="RadAjaxManager1" runat="server">  
                <AjaxSettings> 
                    <rad:AjaxSetting AjaxControlID="checkbox1">  
                        <UpdatedControls> 
                            <rad:AjaxUpdatedControl ControlID="label1" /> 
                            <rad:AjaxUpdatedControl ControlID="button1" /> 
                            <rad:AjaxUpdatedControl ControlID="lblMessage" /> 
                        </UpdatedControls> 
                    </rad:AjaxSetting> 
                </AjaxSettings> 
            </rad:RadAjaxManager> 
              
          
        </div> 
        <asp:Label ID="lblMessage" runat="server" ForeColor="Red"></asp:Label> 
        <table id="Table1" runat="server">  
            <tr> 
                <td><asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True" /></td>  
            </tr> 
            <tr> 
                <td><asp:Label ID="Label1" runat="server" Text="Label"></asp:Label></td>  
            </tr> 
        </table> 
        <table id="Table2" runat="server">  
            <tr> 
                <td><asp:Button ID="Button1" runat="server" Text="Not checked" /></td>  
            </tr> 
        </table> 
      
    </form> 
</body> 
</html> 
 

Code behind file:
Partial Class _Default  
    Inherits System.Web.UI.Page  
 
    Protected Sub Button1_Click(ByVal sender As ObjectByVal e As System.EventArgs) Handles Button1.Click  
 
        If Not Me.CheckBox1.Checked Then 
            Me.lblMessage.Text = "Not checked" 
            Me.lblMessage.Visible = True 
        Else 
            Response.Redirect("page2.aspx")  
        End If 
 
    End Sub 
 
    Protected Sub CheckBox1_CheckedChanged(ByVal sender As ObjectByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged  
        Me.lblMessage.Text = "" 
        Me.Label1.Text = "Checked = " & Me.CheckBox1.Checked.ToString  
        If Me.CheckBox1.Checked Then 
            Me.Button1.Text = "Checked" 
        Else 
            Me.Button1.Text = "Not Checked" 
        End If 
    End Sub 
End Class 

What I expect to happen is that when the user clicks on the button with the checkbox un-checked, the lblMessage would show the text "Not checked".  As noted above, stepping through the code shows that the line is executed, but it doesn't show on the page.

If I comment out or remove the following line on the aspx page and then run the project again, clicking on the button with the checkbox un-checked produces the desired result.

<

 

rad:AjaxUpdatedControl ControlID="button1" />

 


Any ideas as to what could be causing the problem?

I note that the Telerik Ajax Manager version is v2009.2.826.20 (as shown on the aspx page).


4 Answers, 1 is accepted

Sort by
0
Pavel
Telerik team
answered on 17 Feb 2010, 01:35 PM
Hello Rem,

In order to update the label properly when the button is clicked you should add the following ajax settings:
<rad:AjaxSetting AjaxControlID="button1"
    <UpdatedControls>
        <rad:AjaxUpdatedControl ControlID="lblMessage" />
    </UpdatedControls>
</rad:AjaxSetting>


Regards,
Pavel
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Rem
Top achievements
Rank 1
answered on 17 Feb 2010, 07:34 PM
Hi Pavel,

I should have made it clear in my original post.

I specifically want the button to trigger a postback - that is why it is not specified in the ajax manager.  I thought that since it was not "ajaxified" it would do a postback instead of a partial one and update the whole page.  But in this case it doesn't appear to do so.

This is just a simple representation of an issue I found while working on a large project.  When we updated to the version specified below, the issue started to occur.  Before that we were using an older version (I don't have specifics on me at the moment - I'll have to check tomorrow) and it was working fine.
0
Pavel
Telerik team
answered on 18 Feb 2010, 12:34 PM
Hi Rem,

In the markup you have provided you have a setting where checkbox1 updates button1. If you remove the button from the updated controls it will not be wrapped in an update panel and thus will cause regular posbacks. Looking at the markup as it is, there is no reason to keep this setting, however if this is not feasible in your real project you can simply disable ajax when the button in question is clicked, as explained here.

Kind regards,
Pavel
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Rem
Top achievements
Rank 1
answered on 18 Feb 2010, 09:09 PM
Thanks Pavel.

The ScriptManager RegisterPostBackControl method is what I was looking for in this case.  :)
Tags
Ajax
Asked by
Rem
Top achievements
Rank 1
Answers by
Pavel
Telerik team
Rem
Top achievements
Rank 1
Share this question
or