Redirect URL Values Programmatically


At some point you may need to pass non-databound values and other calculated values via URL parameters. This can be done by overriding the ModifyRedirectUrl or Redirect methods.
- Pooja Daga, Technical Support Engineer, Iron Speed, Inc.

May 24, 2006

Introduction

Primary keys, foreign keys and other field values are easily passed from page to page via URL parameters established with settings in the Bindings tab of the Properties dialog. At some point you may need to pass non-databound values and other calculated values via URL parameters. This can be done by overriding the ModifyRedirectUrl or Redirect methods.

In this example, the primary key of a new record is passed from the AddOrdersPage.aspx page to the MyPage.aspx page by specifying a URL parameter in the Bindings tab of the Properties dialog for the “Save” button on AddOrdersPage.aspx. A URL parameter is passed which is a concatenation of two fields, ShipCity and ShipCountry. Two different approaches are illustrated: overriding the ModifyRedirectUrl() method and overriding the Redirect() method, both of which are in the Page class.

Procedure

Step 1: Add the code below in the Page class of MyPage.aspx.cs or vb.

C#, override ModifyRedirectUrl()

public override void ModifyRedirectUrl(BaseClasses.ApplicationEventArgs args)
{
    string myStr = this.ShipCountry.Text + this.ShipCity.Text;
    args.RedirectUrl = args.RedirectUrl + "?myparam=" + myStr;
}

C#, override Redirect()

protected override void Redirect(BaseClasses.ApplicationEventArgs args)
{
    string myStr = this.ShipCountry.Text + this.ShipCity.Text;
    args.RedirectUrl = args.RedirectUrl + "?myparam=" + myStr;
    base.Redirect(args);
}

Visual Basic .NET, override ModifyRedirectUrl()

Public Overrides Sub ModifyRedirectUrl(ByVal args As BaseClasses.ApplicationEventArgs)
    Dim myStr As String = Me.ShipCountry.Text & Me.ShipCity.Text
    args.RedirectUrl = args.RedirectUrl + "?myparam=" + myStr
End Sub

Visual Basic .NET, override Redirect()

Protected Overrides Sub Redirect(ByVal args As BaseClasses.ApplicationEventArgs)
    Dim myStr As String = Me.ShipCountry.Text & Me.ShipCity.Text
    args.RedirectUrl = args.RedirectUrl + "?myparam=" + myStr
    MyBase.Redirect(args)
End Sub

Step 2: Build and run your application.

About the Author

Pooja Daga
Technical Support Engineer, Iron Speed, Inc.

Pooja has experience developing Web applications using .NET technology. She started her career with PCS, a leading software services company headquartered in India and has been with Iron Speed since 2005.

Pooja holds an M.S. degree in Computer Application and a B.S. degree in Electrical engineering from Maharaja Sayajirao University in India.



  Privacy Statement