0

因此,我在 VS 2010 中使用 ASP.NET LINQ to SQL 网站模板。我的网站按预期运行,但我正在尝试进行一些超出我想象的自定义。最初向用户呈现两个选择...

部门 | 雇员

根据他们的选择,他们会看到一个页面,他们可以在其中插入新项目(部门或员工)。这是我的问题...

如果我单击 Departments 并选择 Department_A,我会看到 Department_A 中的所有员工,并且我知道我正在查看 Department_A,因为页面顶部的组合框显示了这一点。此时我选择插入新项目,保存我的新员工,然后我被带回“所有”部门,而不是回到我刚刚离开的 Department_A。我的目标是,如果他们需要为同一部门添加多个员工,则不必让某人点击返回部门。

有任何想法吗?

解决方案: 这是用于实现我的目标的代码,在 Insert.aspx.vb 中......

Protected table As MetaTable

Public Shared Function getPassedVars() As String
    Dim oParams As String = ""
    Dim qString As String = ""
    Dim oSplit As New List(Of String)
    Try
        With HttpContext.Current
            qString = .Request.Url.Query
            If qString.Length > 0 Then 'do we have any passed variables?
                oSplit.AddRange(qString.Split("&"))
                    For i As Integer = 0 To oSplit.Count - 1
                        oParams &= String.Format("{0}{1}", oSplit.Item(i), IIf(i < oSplit.Count - 1, ";", ""))
                    Next
                    Return oParams
                Else
                    Return Nothing
                End If
        End With
    Catch ex As Exception
        Return Nothing
    End Try
End Function

Protected Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs)
    table = DynamicDataRouteHandler.GetRequestMetaTable(Context)
    FormView1.SetMetaTable(table, table.GetColumnValuesFromRoute(Context))
    DetailsDataSource.EntityTypeName = table.EntityType.AssemblyQualifiedName
End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    Title = table.DisplayName
End Sub

Protected Sub FormView1_ItemCommand(ByVal sender As Object, ByVal e As FormViewCommandEventArgs)
    If e.CommandName = DataControlCommands.CancelCommandName Then
        Response.Redirect(table.ListActionPath + getPassedVars())
    End If
End Sub

Protected Sub FormView1_ItemInserted(ByVal sender As Object, ByVal e As FormViewInsertedEventArgs)
    If e.Exception Is Nothing OrElse e.ExceptionHandled Then
        Dim urlVars As String
        For Each s As String In Request.QueryString
            urlVars = "?" & (s & "=") + Request.QueryString(s)
        Next

        Response.Redirect(table.ListActionPath & urlVars)

    End If
End Sub

结束类

4

2 回答 2

0

这是我最终用来执行所需操作的内容。

在 Insert.aspx.vb 中,我将此代码添加到 FormView_ItemInserted Sub...

    For Each s As String In Request.QueryString
           urlVars = "?" & (s & "=") + Request.QueryString(s)
    Next

    Response.Redirect(table.ListActionPath & urlVars)
于 2013-07-03T19:09:21.027 回答
0

使用 Session 来跟踪您所在的位置,然后根据您要使用的逻辑检查该 Session 怎么样?http://wiki.asp.net/page.aspx/57/

于 2013-07-02T17:40:08.313 回答