Change the RedirectUrl of an object and add a URL Parameter

The need for this code came from a record form that needed to have a Save button that saved a new record but continued to display the form in Update mode with the newly saved record.  For all of my tables I use an Identity column for the primary key.  For this to be possible I need another column in the table that is unique.

Note: I also use CodeSmithTools and NetTiers to generate a Data Access Layer (DAL).

The following code assumes I’ve retrieved the record that was just saved (using the generated DAL) and now I’m going to update the RedirectUrl of the record form.  BP is the record object from the DAL.

   Dim S As Session = DataRepository.SessionProvider.GetBySessionName(Session.GetControl(Of MTTextBox)("SessionName").Text)
   If Not S Is Nothing Then
    Session.RedirectUrl.Address = "session_form.aspx"
    Dim up As New InMotion.Web.Controls.UrlParameter
    up.Name = "SessionID"
    up.Value = S.SessionID.ToString()
    Session.RedirectUrl.Parameters.Item("SessionID") = up
   End If


Leave a Reply

Your email address will not be published. Required fields are marked *