aspnet-devexpress-dot-web-dot-aspxwebcontrol-dot-redirectoncallback-x28-system-dot-string-x29.md
Redirects a client to a new URL while processing a callback.
Namespace : DevExpress.Web
Assembly : DevExpress.Web.v25.2.dll
NuGet Package : DevExpress.Web
public static void RedirectOnCallback(
string url
)
Public Shared Sub RedirectOnCallback(
url As String
)
| Name | Type | Description |
|---|---|---|
| url | String |
A string value specifying the new target location.
|
While a callback is being processed on the server, the RedirectOnCallback method enables you to redirect the application to another web resource.
This example demonstrates how to use the RedirectOnCallback(String) method to redirect a user on an AJAX request, for example, ASPxCallbackPanel control callback. With this method, you can implement user login with asynchronous behavior (Login Control will reload the page even if the validation fails or redirect the user on successful validation, but in this example, the login process is done asynchronously).
<head runat="server">
<title>How to redirect user on callback</title>
<script>
function ProcessLoginCallback() {
CallbackPanel.PerformCallback();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<dx:ASPxCallbackPanel ID="CallbackPanel" ClientInstanceName="CallbackPanel" runat="server" Width="200px" OnCallback="CallbackPanel_Callback">
<PanelCollection>
<dx:PanelContent>
<dx:ASPxValidationSummary ID="ValidationSummary" runat="server"></dx:ASPxValidationSummary>
<dx:ASPxLabel ID="LoginLabel" runat="server" Text="Email:"></dx:ASPxLabel>
<dx:ASPxTextBox ID="LoginTextBox" runat="server" Width="170px">
<ValidationSettings>
<RequiredField IsRequired="true" ErrorText="Enter Email" />
<RegularExpression
ValidationExpression="^[-a-z0-9!#$%&'*+/=?^_`{|}~]+(?:\.[-a-z0-9!#$%&'*+/=?^_`{|}~]+)*@(?:[a-z0-9]([-a-z0-9]{0,61}[a-z0-9])?\.)*(?:aero|arpa|asia|biz|cat|com|coop|edu|gov|info|int|jobs|mil|mobi|museum|name|net|org|pro|tel|travel|[a-z][a-z])$"
ErrorText="Bad email address" />
</ValidationSettings>
</dx:ASPxTextBox>
<dx:ASPxLabel ID="PasswordLabel" runat="server" Text="Password:"></dx:ASPxLabel>
<dx:ASPxTextBox ID="PasswordTextBox" runat="server" Password="true" Width="170px">
<ValidationSettings>
<RequiredField IsRequired="true" ErrorText="Password is Required" />
</ValidationSettings>
</dx:ASPxTextBox>
<dx:ASPxButton ID="Button" runat="server" Text="Login" AutoPostBack="false">
<ClientSideEvents Click="ProcessLoginCallback" />
</dx:ASPxButton>
</dx:PanelContent>
</PanelCollection>
</dx:ASPxCallbackPanel>
</form>
</body>
private const string loginUrl = "~/Login.aspx";
protected void CallbackPanel_Callback(object sender, DevExpress.Web.CallbackEventArgsBase e) {
if(ASPxEdit.ValidateEditorsInContainer(sender as ASPxCallbackPanel)) {
ASPxWebControl.RedirectOnCallback(VirtualPathUtility.ToAbsolute(loginUrl));
}
}
Private Const loginUrl As String = "~/Login.aspx"
Protected Sub CallbackPanel_Callback(ByVal sender As Object, ByVal e As DevExpress.Web.CallbackEventArgsBase)
If ASPxEdit.ValidateEditorsInContainer(TryCast(sender, ASPxCallbackPanel)) Then
ASPxWebControl.RedirectOnCallback(VirtualPathUtility.ToAbsolute(loginUrl))
End If
End Sub
See Also