Originariamente inviato da papillon68
Prova ad abilitare EnableViewState nelle proprietà della DropDownList. Funziona ?
FUNZIONA con ViewState abilitato o no. Questa è la pagina completa di collaudo:
pagina
codice:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="a.aspx.vb" Inherits="prove_a" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" EnableViewState="false" Text=""></asp:Label>
<hr />
<asp:Panel ID="Panel1" runat="server">
</asp:Panel>
</div>
</form>
</body>
</html>
codice
codice:
Option Strict On
Imports l = libreria.ModuloWeb
Partial Class prove_a
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim ddlSottoCategoria As New DropDownList
ddlSottoCategoria.Text = Nothing
ddlSottoCategoria.ID = "txtBox" '& x.ToString
ddlSottoCategoria.AutoPostBack = True
Panel1.Controls.Add(ddlSottoCategoria)
ddlSottoCategoria.Visible = True
'If ddlSottoCategoria.Items.Count = 0 Then
' connetti(Session("database"))
' Sql = "SELECT * FROM ecommerce_categorie WHERE appartenenteCategoria = " & ddlCategoria.SelectedValue & " AND titoloCategoria <> 'Tutte'"
' objCmd = New SqlCommand(Sql, objConn)
' objDR = objCmd.ExecuteReader()
' Dim itm As New ListItem
' itm.Text = "Seleziona una categoria"
' itm.Value = 0
' ddlSottoCategoria.Items.Add(itm)
' Do While (objDR.Read())
' Dim itm2 As New ListItem
' itm2.Text = objDR("titoloCategoria").ToString()
' itm2.Value = objDR("idCategoria")
' ddlSottoCategoria.Items.Add(itm2)
' Loop
'End If
ddlSottoCategoria.EnableViewState = False
AddHandler ddlSottoCategoria.SelectedIndexChanged, AddressOf ddlSottoCategoria_SelectedIndexChanged
msole.FillListControl(ddlSottoCategoria, gl.StringaConnessioneRegioniProvinceComune, "regioni", "nome_regione", "id_regione", New ListItem("", ""))
End Sub
Protected Sub ddlSottoCategoria_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Dim d As DropDownList = DirectCast(sender, DropDownList)
Me.Label1.Text = d.SelectedItem.Text
End Sub
End Class