我有一个页面,它在pre_init上构建了许多带有控件的updatepanel。 (有时我在另一个更新面板中有更新面板)
在表格单元格中,我有一个下拉列表和一个复选框。他们都是自动堆栈。它们后面有完全相同的代码(一个在checkedChanged上,另一个在selectedindexchaged上)。
该复选框将完美运行。另一方面,下拉列表导致整页重新加载...
任何人都知道为什么?我已经失去了很多时间......
谢谢!
CodeBehind: 公共类ProductBuilder2 继承System.Web.UI.Page
Private Sub ProductBuilder2_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
BuildProduct(Request.QueryString("ProductID"))
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
BindProductID()
End If
End Sub
Protected Sub BuildProduct(ByVal ProductID As Integer)
Dim xMasterProd As New cProduct(ProductID)
If xMasterProd.IsGroup Then
For Each xKitProd As cKit In xMasterProd.Kit
If xKitProd.Product.IsGroup Then
Renderer.Controls.Add(CreateGroup(xKitProd.Product, xKitProd.DoNotInclude))
End If
If Not xKitProd.Product.IsGroup Then
Renderer.Controls.Add(CreateProduct(xKitProd.Product, xKitProd.DoNotInclude))
End If
Next
End If
If Not xMasterProd.IsGroup Then
Renderer.Controls.Add(CreateProduct(xMasterProd, False))
End If
End Sub
Public Function CreateProduct(ByRef xProduct As cProduct, _
ByVal DoNotInclude As Boolean) As UpdatePanel
Dim xTable As New Table
Dim xTR As New TableRow
Dim xTD As New TableCell
xTable.CssClass = "Container"
Dim lblProductName As New Label
lblProductName.Text = xProduct.Name
xTD.CssClass = "ProductName"
xTD.Attributes.Add("colspan", "3")
xTD.Controls.Add(lblProductName)
xTR.Controls.Add(xTD)
If DoNotInclude Then
Dim xChkDNI As New CheckBox
xChkDNI.Text = "Do not include"
xChkDNI.CssClass = "DoNotInclude"
xChkDNI.AutoPostBack = True
AddHandler xChkDNI.CheckedChanged, AddressOf DoNotInclude_CheckedChanged
xTD.Controls.Add(xChkDNI)
xTR.Controls.Add(xTD)
End If
xTable.Controls.Add(xTR)
xTR = New TableRow
xTD = New TableCell
Dim lblProductDescription As New Label
lblProductDescription.Text = xProduct.Description
xTD.Attributes.Add("colspan", "3")
xTD.CssClass = "ProductDescription"
xTD.Controls.Add(lblProductDescription)
xTR.Controls.Add(xTD)
xTable.Controls.Add(xTR)
For Each xOpt As cOption In xProduct.OptionLabels
xTR = New TableRow
xTD = New TableCell
xTD.CssClass = "ProductDescription"
xTD.Style.Add("width", "150px;")
Dim xlblOptionLabel As New Label
xlblOptionLabel.Text = xOpt.LabelText & " : "
xTD.Controls.Add(xlblOptionLabel)
xTR.Controls.Add(xTD)
xTD = New TableCell
Dim DropOptionID As New DropDownList
xTD.Controls.Add(DropOptionID)
xTR.Controls.Add(xTD)
xTable.Controls.Add(xTR)
For Each OptionID As cOption In xOpt.Options
Dim xListItem As New ListItem
xListItem.Text = OptionID.LabelText
xListItem.Value = OptionID.ID
If OptionID.IsDefault Then xListItem.Selected = True
DropOptionID.Items.Add(xListItem)
Next
xTD = New TableCell
Dim lblMessage As New Label
lblMessage.Text = xOpt.Message
lblMessage.CssClass = "Message"
If xOpt.Message = "" Then lblMessage.Visible = False
xTD.Controls.Add(lblMessage)
xTR.Controls.Add(xTD)
xTable.Controls.Add(xTR)
Next
Dim UP As UpdatePanel = CreateUpdatePanel("UP-" & xProduct.ID)
UP.ContentTemplateContainer.Controls.Add(xTable)
Return UP
End Function
Public Function CreateGroup(ByRef xProduct As cProduct, _
ByVal DoNotInclude As Boolean) As UpdatePanel
'1st create the group container
Dim xTable As New Table
Dim xTR As New TableRow
Dim xTD As New TableCell
xTable.CssClass = "Container"
xTD.CssClass = "ProductGroup"
xTD.Attributes.Add("colspan", "3")
Dim xLabel As New Label
xLabel.Text = xProduct.Name & " : "
xTD.Controls.Add(xLabel)
Dim DropProdID As New DropDownList
DropProdID.AutoPostBack = True
DropProdID.ID = "DropProdID" & xProduct.ID
AddHandler DropProdID.SelectedIndexChanged, AddressOf DropProdID_SelectedIndexChanged
Dim Trigger As New PostBackTrigger
Trigger.ControlID = DropProdID.ID
xTD.Controls.Add(DropProdID)
xTR.Controls.Add(xTD)
If DoNotInclude Then
Dim xChkDNI As New CheckBox
xChkDNI.Text = "Do not include"
xChkDNI.CssClass = "DoNotInclude"
xChkDNI.AutoPostBack = True
AddHandler xChkDNI.CheckedChanged, AddressOf DoNotInclude_CheckedChanged
xTD.Controls.Add(xChkDNI)
xTR.Controls.Add(xTD)
End If
xTable.Controls.Add(xTR)
For Each xKitProd As cKit In xProduct.Kit
Dim xListItem As New ListItem
xListItem.Text = xKitProd.Product.Name
xListItem.Value = xKitProd.Product.ID
If xKitProd.IsDefault Then
xListItem.Selected = True
If Not xKitProd.Product.IsGroup Then
xTR = New TableRow
xTD = New TableCell
xTD.Controls.Add(CreateProduct(xKitProd.Product, xKitProd.DoNotInclude))
xTR.Controls.Add(xTD)
xTable.Controls.Add(xTR)
End If
For Each xProd As cKit In xKitProd.Product.Kit
xTR = New TableRow
xTD = New TableCell
xTD.Controls.Add(CreateProduct(xProd.Product, xProd.DoNotInclude))
xTR.Controls.Add(xTD)
xTable.Controls.Add(xTR)
Next
End If
DropProdID.Items.Add(xListItem)
Next
Dim UP As UpdatePanel = CreateUpdatePanel("UP-" & xProduct.ID)
UP.ContentTemplateContainer.Controls.Add(xTable)
UP.Triggers.Add(Trigger)
Return UP
End Function
Protected Sub DoNotInclude_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Dim xChk As CheckBox = CType(sender, CheckBox)
Dim xTable As Table = xChk.Parent.Parent.Parent
Dim UP As UpdatePanel = xTable.Parent.Parent
Dim Index As Integer = 1
For Each xTR As TableRow In xTable.Rows
If Index <> 1 Then
xTR.Visible = Not xChk.Checked
End If
Index += 1
Next
UP.Update()
End Sub
Protected Sub DropProdID_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Dim DropProdID As DropDownList = CType(sender, DropDownList)
Dim xTable As Table = DropProdID.Parent.Parent.Parent
Dim UP As UpdatePanel = xTable.Parent.Parent
Dim Index As Integer = 1
For Each xTR As TableRow In xTable.Rows
If Index <> 1 Then
xTR.Visible = False
'xTable.Rows.RemoveAt(Index)
End If
Index += 1
Next
'Dim xProduct As New cProduct(DropProdID.SelectedValue)
'If xProduct.IsGroup Then
'End If
'If Not xProduct.IsGroup Then
' Dim xTR As New TableRow
' Dim xTD As New TableCell
' xTD.Controls.Add(CreateProduct(xProduct, False))
' xTR.Controls.Add(xTD)
' xTable.Controls.Add(xTR)
'End If
UP.Update()
End Sub
Public Sub RenderPanel(ByRef xPanel As Panel)
Renderer.Controls.Add(xPanel)
End Sub
Public Function CreateUpdatePanel(ByVal ID As String) As UpdatePanel
Dim UP As New UpdatePanel()
UP.ID = ID
UP.UpdateMode = UpdatePanelUpdateMode.Conditional
UP.RenderMode = UpdatePanelRenderMode.Inline
UP.ChildrenAsTriggers = False
Return UP
End Function
Private Sub ProductID_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ProductID.SelectedIndexChanged
Response.Redirect("ProductBuilder2.aspx?ProductID=" & ProductID.SelectedValue)
End Sub
Protected Sub BindProductID()
Dim xProd As New cProduct
ProductID.DataTextField = "Name"
ProductID.DataValueField = "ID"
ProductID.DataSource = xProd.ToList()
ProductID.DataBind()
End Sub
结束班
.aspx:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="ProductBuilder2.aspx.vb" Inherits="OLO3._0._0.ProductBuilder2" %>
&lt;%@ Register Assembly =“Telerik.Web.UI”Namespace =“Telerik.Web.UI”TagPrefix =“telerik”%&gt;
OLO3.0 / Product Builder .Container {margin:10px 10px 10px 10px; background-color:#ffffff; border:1px solid#c2c2c2;宽度:98%;} .ProductGroup {background-color:#c3e7b4; border:1px solid#417b2a;填充:5px 5px 5px 5px;字体:10pt Verdana; font-weight:bold;颜色:#417b2a;} .ProductName {background-color:#d8e4f0; border:1px solid#567db0;填充:5px 5px 5px 5px;字体:10pt Verdana; font-weight:bold;颜色:#567db0;} .ProductDescription {padding:5px 5px 5px 5px;字体:9pt Verdana;} .Message {background-color:#f8d7d8; border:1px solid#ed2227;填充:2px 2px 2px 2px;字体:10pt Verdana;} .DoNotInclude {font:9pt Verdana; margin-left:20px; font-weight:normal;}
<asp:ScriptManager ID="SM1" runat="server"></asp:ScriptManager>
<telerik:RadFormDecorator ID="RadFormDecorator1" runat="server" Skin="Sitefinity" DecoratedControls="All" />
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="3" align="center"><img src="../Img/Logo.png" alt="Paradox" style="padding-top: 20px; padding-bottom: 20px;" /></td>
</tr>
<tr>
<td style="width: 150px;" valign="top">Product Tree (150px)
<asp:DropDownList ID="ProductID" runat="server" AppendDataBoundItems="true" Width="140" AutoPostBack="true"><asp:ListItem Text="Select a product" Value=""></asp:ListItem></asp:DropDownList>
</td>
<td valign="top" style="background-color: #f2f2f2;">
<asp:Panel ID="Renderer" runat="server">
</asp:Panel>
<asp:UpdatePanel ID="UPMessage" runat="server" UpdateMode="Conditional" RenderMode="Inline">
<ContentTemplate>
<asp:Label ID="lblmessage" runat="server"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</td>
<td style="width: 300px;" valign="top">Cart Resume (300px)</td>
</tr>
<tr>
<td colspan="3">Footer</td>
</tr>
</table>
</form>
答案 0 :(得分:0)
如果更新面板中有更新面板,则可能无法触发面板外部的部分回发。可以确保使用内联或代码隐藏指定触发器。没有看到代码,这就是我的建议。
答案 1 :(得分:0)
发现它......必须设置ChildrendHasTrigger = true ...:P