Skip to content

Commit

Permalink
:kb(ajax): adjust code blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
P1l3T0 committed Feb 22, 2024
1 parent f177a06 commit 6c558e6
Showing 1 changed file with 61 additions and 61 deletions.
122 changes: 61 additions & 61 deletions knowledge-base/radajax-and-webusercontrols.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,72 +135,70 @@ As to the AJAX settings, if the markup settings within the user control do not s

The following example demonstrates how to add `AjaxSettings` to the AjaxManager.

* On the main form:

````ASP.NET
<form id="Form1" method="post" runat="server">
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
</telerik:RadScriptManager>
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
</telerik:RadAjaxManager>
<uc1:webusercontrol1 id="WebUserControl1" runat="server"></uc1:webusercontrol1>
</form>
````

* On the user control markup:

````ASP.NET
<asp:Button ID="Button1" Text="Button" runat="server"></asp:Button>
<asp:Label ID="Label1" runat="server">Label</asp:Label>
````

* In the page code-behind:

````C#
protected void Page_Load(object sender, EventArgs e)
{
//Get the WebUserControl
UserControl MyControl = (UserControl)Page.FindControl("WebUserControl1");

//Get user control's button and label
Button MyButton = (Button)MyControl.FindControl("Button1");
Label MyLabel = (Label)MyControl.FindControl("Label1");

//Add the necessary AJAX setting programmatically
RadAjaxManager1.AjaxSettings.AddAjaxSetting(MyButton, MyLabel);
}
````
````VB
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
'Get the WebUserControl
Dim MyControl As UserControl = CType(Page.FindControl("WebUserControl1"), UserControl)

'Get user control's button and label
Dim MyButton As Button = CType(MyControl.FindControl("Button1"), Button)
Dim MyLabel As Label = CType(MyControl.FindControl("Label1"), Label)

'Add the necessary AJAX setting programmatically
RadAjaxManager1.AjaxSettings.AddAjaxSetting(MyButton, MyLabel)
End Sub
````
On the main form:

````ASP.NET
<form id="Form1" method="post" runat="server">
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
</telerik:RadScriptManager>
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
</telerik:RadAjaxManager>
<uc1:webusercontrol1 id="WebUserControl1" runat="server"></uc1:webusercontrol1>
</form>
````

On the user control markup:

````ASP.NET
<asp:Button ID="Button1" Text="Button" runat="server"></asp:Button>
<asp:Label ID="Label1" runat="server">Label</asp:Label>
````

In the page code-behind:

````C#
protected void Page_Load(object sender, EventArgs e)
{
//Get the WebUserControl
UserControl MyControl = (UserControl)Page.FindControl("WebUserControl1");

//Get user control's button and label
Button MyButton = (Button)MyControl.FindControl("Button1");
Label MyLabel = (Label)MyControl.FindControl("Label1");

//Add the necessary AJAX setting programmatically
RadAjaxManager1.AjaxSettings.AddAjaxSetting(MyButton, MyLabel);
}
````
````VB
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
'Get the WebUserControl
Dim MyControl As UserControl = CType(Page.FindControl("WebUserControl1"), UserControl)

'Get user control's button and label
Dim MyButton As Button = CType(MyControl.FindControl("Button1"), Button)
Dim MyLabel As Label = CType(MyControl.FindControl("Label1"), Label)

'Add the necessary AJAX setting programmatically
RadAjaxManager1.AjaxSettings.AddAjaxSetting(MyButton, MyLabel)
End Sub
````

You can use the `RadAjaxManager.GetCurrent(Page)` method to reference the AjaxManager in the `Page_Load` of the user control and add the `AjaxSettings` there as well.

The following example demonstrates how to achieve this on the user control code-behind.

````C#
protected void Button1_Click(object sender, System.EventArgs e)
{
Label1.Text = DateTime.Now.ToLongTimeString();
}
````
````VB
Protected Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Label1.Text = DateTime.Now
End Sub
````

````C#
protected void Button1_Click(object sender, System.EventArgs e)
{
Label1.Text = DateTime.Now.ToLongTimeString();
}
````
````VB
Protected Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Label1.Text = DateTime.Now
End Sub
````



Expand All @@ -212,3 +210,5 @@ The following example demonstrates how to achieve this on the user control code-
* [Add AjaxSettings Programmatically]({%slug ajaxmanager/how-to/add-ajaxsettings-programmatically%})

* [User Controls](https://demos.telerik.com/aspnet-ajax/Ajax/Examples/Manager/UserControl/DefaultCS.aspx)


0 comments on commit 6c558e6

Please sign in to comment.