DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Thu, 9 Aug 2007 19:44:40 +0800,    posted on: microsoft.public.dotnet.framework.aspnet        back       

Thread Index
  1    MING@HongKong


Access Control in WebUserControl Fail via aspx page   
I have a question about modify standard web control (textbox,listbox,label 
etc....) inside ascx via aspx page.
the question detail is :
i have a aspx page( main.aspx) and a WebUserControl (MyControl.ascx)

main.aspx contain a button (btnadditem) and the control.ascx.

and control.ascx have one Listbox (Lstbox) and a Subroutine (AddItem) who 
add some dummy item to (Lstbox) by For...Next ....

everything is work fine , but only not working is when i press the 
btnadditem on main.aspx ,it WILL FIRE the Sub : AddItem and Postback

But the ListItem is not add the Listbox. But i believe that the sub have 
been run, because i have add Debug.writeline(something) inside the for..next

I have added the <%@ Reference Control="~/MyControl.ascx" %> to main.aspx, 
but it not help.

below is the source code for reference:

main.aspx.vb

1    Partial Class _Default
2        Inherits System.Web.UI.Page
3        Protected Sub btnadditem_Click(ByVal sender As Object, ByVal e As 
System.EventArgs) Handles btnadditem.Click
4            Dim ctl As MyControl= CType(Page.LoadControl("MyControl.ascx"), 
MyControl)
5            ctl.addItem()
6
7        End Sub
8    End Class



MyControl.ascx.vb

1    Imports System.Diagnostics
2
3    Partial Class MyControl
4        Inherits System.Web.UI.UserControl
5
6        Protected Sub Page_Load(ByVal sender As Object, ByVal e As 
System.EventArgs) Handles Me.Load
7            ' addItem() ' NOT USE                LstBox.items.add("Dummy") 
LstBox.items.add("Dummy")
8        End Sub
9
10
11       Sub addItem()
12           LstBox.Items.Clear()
13           Response.Write("LstBox Clear : " & LstBox.Items.Count & "<BR>")
14           Response.Write("LstBox Start Add Item : <BR>")
15           For i As Integer = 0 To 10
16               Dim itemx As New ListItem
17               itemx.Text = Rnd(99)
18               itemx.Value = Rnd(99)
19               LstBox.Items.Add(itemx)
20               Response.Write(i & vbTab & itemx.Text & vbTab & itemx.Value 
& "<BR>") 'It can show the i and itemx
21           Next
22
23       End Sub
24
25   End Class

the result is , the LstBox have not clear the 2 dummy item and have add the 
listitem, but the i will print out follow 1,2,3,4,5,6,7,8....with the 
Rnd(99)
But when i uncomment line 7, the Sub:additem will run correctly, so i think 
the problem not come from Sub:additem.
i find answer on google, but really not much result i got.Thx for help
Date:Thu, 9 Aug 2007 19:44:40 +0800   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us