在普通的vb类中,我使用下拉列表加载usercontrol
Dim products As UserControl = Page.LoadControl("~/Controls/Products.ascx")
products.ID = "Products"
tile.Controls.Add(products)
但我的onindexchanged事件(在usercontrol中)由于某种原因没有触发。
代码:
Partial Class Controls_Products
Inherits System.Web.UI.UserControl
Public Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Dim myPage As BasePage = CType(Me.Page, BasePage)
Dim dsProducts As DataSet = eyeCatalogueFunctions.GetProduct(0, myPage.GetLang, myPage.GetCustid, 0, "", 0, Nothing, 0)
If Not IsNothing(dsProducts) AndAlso dsProducts.Tables.Count > 0 AndAlso dsProducts.Tables(0).Rows.Count > 0 Then
With Me.ddlProducts
.DataSource = dsProducts.Tables(0)
.DataTextField = "product_nam"
.DataValueField = "seqproduct"
.DataBind()
End With
Me.lblTest.Text = Me.ddlProducts.Items(0).Text
End If
End If
End Sub
Protected Sub ddlProducts_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ddlProducts.SelectedIndexChanged
'Do something
End Sub
usercontrol没什么特别的:
<%@ Control Language="VB" AutoEventWireup="true" CodeFile="Products.ascx.vb" Inherits="Controls_Products" EnableViewState="true" %>
任何想法?
答案 0 :(得分:0)
检查 AutoPostBack 属性设置为 true 。
可以将其设置为 products.AutoPostBack = true