How to count button's click number?

sheriffdaone

New member
Joined
Oct 4, 2006
Messages
3
Programming Experience
Beginner
i am tryin to reach all the controls those were created automaticly on run-time. But whenever i try to reach it i get an "NullReferenceException" error. Here is what i wrote in VB.NET code;

VB.NET:
[FONT=Courier New]Dim i As Integer = 0 
While i <= ButtonClick 
 myUpload = CType(pnlUpload.FindControl("upload_" + ButtonClick.ToString), FileUpload) 
 If myUpload.HasFile Then 
   upload(myUpload.PostedFile.FileName) 
   lblSonuc.Text = "basari" 
 End If 
 System.Math.Min(System.Threading.Interlocked.Increment(i),i-1) 
End While[/FONT]

and to create them on the run-time i wrote those lines;

VB.NET:
[FONT=Courier New]Public Property ButtonClick() As Integer 
 Get 
   Return CType(ViewState("ButtonClick"), Integer) 
 End Get 
 Set 
   ViewState("ButtonClick") = value 
 End Set 
End Property 

Protected Sub lnkEkle_Click(ByVal sender As Object, ByVal e As EventArgs) 
 System.Threading.Interlocked.Increment(ButtonClick) 
 Dim i As Integer = 0 
 While i < ButtonClick 
   myUpload = New FileUpload 
   myUpload.ID = "upload_" + ButtonClick.ToString 
   Me.pnlUpload.Controls.Add(myUpload) 
   System.Math.Min(System.Threading.Interlocked.Increment(i),i-1) 
 End While 
 lblSonuc.Visible = True 
End Sub[/FONT]


so in the first lines those i wrote i get the error. if (myUpload.HasFile) this returns false because myUpload object returns null? How can i fix this issue?

Thanks
 
Back
Top