New to Telerik UI for ASP.NET AJAX? Start a free 30-day trial
How to Trigger Server-Side Click Event in RadFloatingActionButton for ASP.NET AJAX
Updated over 6 months ago
Environment
| Property | Value |
|---|---|
| Product | RadFloatingActionButton for ASP.NET AJAX |
| Version | all |
Description
I want to trigger a server-side click event in RadFloatingActionButton for ASP.NET AJAX, but it is not getting triggered by default.
Solution
By default, the RadFloatingActionButton does not trigger server-side events. However, you can still achieve this by making a PostBack using the __doPostBack() function.
Here's how:
- Add the following JavaScript code to your page:
javascript
<script>
function OnClientClicked(ev) {
var floatingActionButtonId = ev.get_id();
__doPostBack(floatingActionButtonId, "SomeArguments");
}
</script>
- Modify your RadFloatingActionButton control to include the
OnClientClickedclient event:
html
<telerik:RadFloatingActionButton runat="server" ID="RadFloatingActionButton1" Icon="save" PositionMode="Fixed" Text="Save">
<ClientEvents OnClick="OnClientClicked" />
</telerik:RadFloatingActionButton>
- In the code-behind (C#), capture the event in the
Page_Loadmethod:
csharp
protected void Page_Load(object sender, EventArgs e)
{
string eventTarget = Request["__EVENTTARGET"]; // RadFloatingActionButton1
if (!string.IsNullOrWhiteSpace(eventTarget) && eventTarget == RadFloatingActionButton1.ClientID)
{
string parameter = Request["__EVENTARGUMENT"]; // SomeArguments
// Handle the event here
}
}That's it! You can now trigger a server-side click event in RadFloatingActionButton for ASP.NET AJAX using the provided solution.
Notes
Make sure to replace RadFloatingActionButton1 with the actual ID of your RadFloatingActionButton control in the Page_Load method.