Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Server.Transfer or reset controls

Status
Not open for further replies.

jonbatts

Programmer
Apr 12, 2005
114
US
I've got a page that (though part of an application) is stand-alone in that when a user is finished with the page and submits the information it saves the data, and returns to its original state. It's got 56 radio buttons (in pairs), 31 textboxes, and 5 dropdownlists. When the user is finished modifying the controls and clicks the "Submit" button, I'll save the data and then do one of two things. Reset the page using a function, or do a Server.Transfer to the same page. Here's the code I'm using to "reset" the page.
Code:
...
    For Each ctlCurrent As Control In Me.Controls
        ClearControls(ctlCurrent)
    Next
...
Private Sub ClearControls(ByRef controlToClear As Control)
    Dim rdoCurrent As RadioButton
    Dim txtCurrent As TextBox
    Dim ddlCurrent As DropDownList
    For Each ctlCurrent As Control In controlToClear.Controls
        ClearControls(ctlCurrent)
    Next

    Select Case controlToClear.GetType.ToString
        Case "System.Web.UI.WebControls.RadioButton"
            rdoCurrent = controlToClear
            If rdoCurrent.ID.Substring(controlToClear.ID.Length - 1) = "1" Then
                rdoCurrent.Checked = True
            Else
                rdoCurrent.Checked = False
            End If
        Case "System.Web.UI.WebControls.TextBox"
            txtCurrent = controlToClear
            txtCurrent.Text = ""
        Case "System.Web.UI.WebControls.DropDownList"
            ddlCurrent = controlToClear
            ddlCurrent.SelectedIndex = -1
    End Select
End Sub
Considering efficiency of running this code versus loading a new page (what Server.Transfer would basically be doing) which one is more efficient? Thanks, and have a great day.
 
I'd have thought that redirecting the user back to the page would be quicker but the only way you'll know (as each situation could be different) is to do your own tests and try both methods.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
I think it's probably easiest to just do a Server.Transfer to the same page, it's one line of code vs 25 and much faster.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top