Question

I am just experimenting and trying to make Rad Ajax work. I created two buttons and two events associated with them. The First Button changes the text of Lable1 to Hi and Second button changes the Label2 to Bye without loading the whole page.

Here is the code.

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="Button1">
 <UpdatedControls>
  <telerik:AjaxUpdatedControl ControlID="Panel1" />
  <telerik:AjaxUpdatedControl ControlID="Label1" />
 </UpdatedControls>
</telerik:AjaxSetting>
<telerik:AjaxSetting AjaxControlID="Button2">
 <UpdatedControls>
  <telerik:AjaxUpdatedControl ControlID="Panel1" />
  <telerik:AjaxUpdatedControl ControlID="Label1" />
 </UpdatedControls>
 </telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Hi" 
Width="41px" />
<asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="Bye" />
<br />
<asp:Panel ID="Panel1" runat="server">
<asp:Label ID="Label1" runat="server" Text="Label1"></asp:Label>
</asp:Panel>
<asp:Panel ID="Panel2" runat="server">
   <asp:Label ID="Label2" runat="server" Text="Label2"></asp:Label>
</asp:Panel>

Behind Code:

   protected void Page_Load(object sender, EventArgs e)
    {
        if(IsPostBack)
        Response.Write("Page Loaded");
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Label1.Text = "Hi";

    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        Label2.Text = "Bye";
    }

This code works perfect without RadAjax but I want to implement it with Rad Ajax to update only Label1 and Label2 when required without loading the page.

Can someone please help me in this problem?

Thanks.

Was it helpful?

Solution

You cannot use Response object when using ASP.NET Ajax.

In addition, you have typo in UpdatedControls tag - see in the comment.

protected void Page_Load(object sender, EventArgs e)
{
  // You cannot have Response.Write here.
}

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="Button1">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="Panel1" />
                <telerik:AjaxUpdatedControl ControlID="Label1" />
            </UpdatedControls>
        </telerik:AjaxSetting>
        <telerik:AjaxSetting AjaxControlID="Button2">
            <UpdatedControls>
                <%-- Must be Panel2 and Label2 --%>
                <telerik:AjaxUpdatedControl ControlID="Panel2" /> 
                <telerik:AjaxUpdatedControl ControlID="Label2" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top