我想要实现的基本上是这样的:
我的问题是,当我触发MyTreeView.SelectedNodeChanged事件时,我将重定向到我在对话框弹出窗口中显示的aspx页面。我有什么办法可以防止这种情况发生,或者包含回发?我包括了我的代码,但是我猜这将是我必须在aspx中解决的问题吗?
以下是一些代码:
ReportSave.aspx-在对话框窗口中
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="ReportSave.aspx.vb" Inherits="ReportSave" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Save Report As</title>
<link href="ReportSaveStyle.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<form id="formReportSave" runat="server">
<div class="container">
<asp:Label class="report-list-title" ID="lblReportList" runat="server" Text="Report List"></asp:Label>
<asp:TreeView class="report-list-items" ID="trvReportList" runat="server"></asp:TreeView>
<asp:Label class="category-tree-title" ID="lblReportCategory" runat="server" Text="Report Category"></asp:Label>
<asp:TreeView class="category-tree-items" ID="trvCategoryView" runat="server"></asp:TreeView>
<asp:Label class="save-input-title" ID="lblReportName" runat="server" Text="Report Name"></asp:Label>
<asp:TextBox class="save-input-textbox" ID="tbReportName" runat="server"></asp:TextBox>
<asp:Button class="save-button1" ID="btnOK" runat="server" Text="OK" />
<asp:Button class="save-button2" ID="btnCancel" runat="server" Text="Cancel" />
</div>
</form>
</body>
</html>
后端代码-ReportSave.aspx.vb
Private Sub trvCategoryView_SelectedNodeChanged(sender As Object, e As EventArgs) Handles trvCategoryView.SelectedNodeChanged
Try
'Dim li As ListItem
'li = cblCategoryView.SelectedItem
Dim node As TreeNode
node = trvCategoryView.SelectedNode
' handle all categories
If node.Value.ToString.ToUpper = "NEW CATEGORY" Then
Dim strNC As String = InputBox("Enter Name for New Category", "Create Category")
If strNC = "" Then
Exit Sub
End If
If strNC.ToUpper = "NEW CATEGORY" Then
ClientScript.RegisterStartupScript(Me.GetType(), "myalert", "window.alert('You can't have a Category Called New Category. Sorry!');", True)
Exit Sub
End If
Dim conn As New SqlClient.SqlConnection(_ConnectionString)
conn.Open()
Dim cmd As New SqlClient.SqlCommand("Select recordno from Reports where ReportType = '" & strNC & "'", conn)
Dim strresult As String = cmd.ExecuteScalar
If IsNothing(strresult) Then
Dim temp As TreeNode = New TreeNode(strNC, strNC, "Images/file.png")
' Dim temp As ListItem = New ListItem(strNC, strNC)
'lvCategoryView.Items.Add(temp)
'SetSelectedListItem(lvCategoryView.Items(lvCategoryView.Items.Count - 1))
'cblCategoryView.Items.Add(temp)
trvCategoryView.Nodes.Add(temp)
FillReports()
lblReportList.Text = "Report List for Group " & trvCategoryView.SelectedValue.ToString
' cblCategoryView.SelectedValue
ClientScript.RegisterStartupScript(Me.GetType(), "myalert", "window.alert('That Report Group Already Exists');", True)
End If
cmd.Dispose()
cmd = Nothing
conn.Close()
conn.Dispose()
conn = Nothing
Exit Sub
Else
'SetSelectedListItem(li)
FillReports()
lblReportList.Text = "Report List for Group " & trvCategoryView.SelectedValue.ToString
'cblCategoryView.SelectedValue.ToString
End If
Catch ex As Exception
End Try
End Sub
感谢您的任何帮助!我是Web开发以及ASP.NET的新手。 :)
答案 0 :(得分:1)
我假设您正在将此表单加载到iframe中,并且可能会想到问题出在MyTreeView.SelectedNodeChanged事件或父页面本身的实现上。
思维开阔,Web窗体可能有替代解决方案来实现您的目标。我最不喜欢实施iframe。根据您的特定要求,这些选项可能对您更好。