我正在尝试并尝试使Rad Ajax工作。我创建了两个按钮和两个与它们相关的事件。第一个按钮将Lable1的文本更改为Hi,第二个按钮将Label2更改为Bye而不加载整个页面。
这是代码。
<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>
代码背后:
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";
}
这段代码在没有RadAjax的情况下工作正常,但是我想用Rad Ajax实现它,在需要时只更新Label1和Label2而不加载页面。
有人可以帮我解决这个问题吗?
感谢。
答案 0 :(得分:1)
使用ASP.NET Ajax时无法使用Response对象。
此外,您在UpdatedControls
标记中输入错字 - 请参阅评论。
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>