Creating Server control's Control Array

  • Thread starter Thread starter vivek
  • Start date Start date
V

vivek

Hello Every body,

I am tring to make an array of server controls with array
indes can change dynamically.
But I was not able to get the refrence of the control
outside the scope in which they were created.
can any body help me by sending a piece of sample code.
Regards
Vivek
 
Can you show us the code that you have so far and how/where it is not
working?
 
Hello Friend...

Below is the code I am Using. I a not able to get the refrence of the
Text boxes That I create Dynamically in the function
"TotalExperience()"..

The Code Starts now

Imports System
Imports System.Data.SqlClient
Imports System.Text
Imports System.IO
Imports System.Xml


Public Class frmResume2
Inherits System.Web.UI.Page

Protected WithEvents Form1 As System.Web.UI.HtmlControls.HtmlForm
Protected WithEvents txtCurrentSalary As
System.Web.UI.WebControls.TextBox
Protected WithEvents pnlText As System.Web.UI.WebControls.Panel
Protected WithEvents pnlCaption As System.Web.UI.WebControls.Panel
Protected WithEvents cboCompaniesWorkedIn As
System.Web.UI.WebControls.DropDownList
Protected WithEvents txtCertifications As
System.Web.UI.WebControls.TextBox
Protected WithEvents cboProfYearPassing As
System.Web.UI.WebControls.DropDownList
Protected WithEvents TxtProfInstitute As
System.Web.UI.WebControls.TextBox
Protected WithEvents txtProfSpecilization As
System.Web.UI.WebControls.TextBox
Protected WithEvents cboProfCourse As
System.Web.UI.WebControls.DropDownList
Protected WithEvents cboYearPassing As
System.Web.UI.WebControls.DropDownList
Protected WithEvents txtInstitute As
System.Web.UI.WebControls.TextBox
Protected WithEvents txtSpecilization As
System.Web.UI.WebControls.TextBox
Protected WithEvents cboCourse As
System.Web.UI.WebControls.DropDownList
Protected WithEvents cmdLogOut As
System.Web.UI.WebControls.ImageButton
Protected WithEvents cmdClear As
System.Web.UI.WebControls.ImageButton
Protected WithEvents cmdSavenNext As
System.Web.UI.WebControls.ImageButton
Protected WithEvents cmdLogOut1 As
System.Web.UI.WebControls.ImageButton
Protected WithEvents cmdClear1 As
System.Web.UI.WebControls.ImageButton
Protected WithEvents cmdSavenNext1 As
System.Web.UI.WebControls.ImageButton
Protected WithEvents FilePath As
System.Web.UI.HtmlControls.HtmlInputFile
Protected WithEvents Xml1 As System.Web.UI.WebControls.Xml

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

#Region "User Defined Controls"
Public Shared textBox1 As New Web.UI.WebControls.TextBox()
Public Shared Label1() As Web.UI.WebControls.Label
#End Region

Dim iclsConnection As New clsConnection()
Dim iSqlConnection As New SqlConnection()

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

Private Sub cboCompaniesWorkedIn_SelectedIndexChanged(ByVal sender
As System.Object, ByVal e As System.EventArgs) Handles
cboCompaniesWorkedIn.SelectedIndexChanged
Dim idx As Integer
Dim Unit1 As New System.Web.UI.WebControls.Unit()
ReDim textBox1(3 * CInt(cboCompaniesWorkedIn.SelectedItem.Text))
AS Web.UI.WebControls.TextBox()
ReDim Label1(3 * CInt(cboCompaniesWorkedIn.SelectedItem.Text))
For idx = 1 To (CInt(cboCompaniesWorkedIn.SelectedItem.Text) *
3)
Dim textBox1 As New Web.UI.WebControls.TextBox()
textBox1.ID = "testbox" & CStr(idx)
pnlText.Controls.Add(textBox1)
textBox1.Width = Unit1.Percentage(100)
Label1(idx) = New Web.UI.WebControls.Label()
Label1(idx).Width = Unit1.Percentage(100)
Label1(idx).Height = textBox1.Height
If ((idx Mod 3) = 1) Then
Label1(idx).Text = "Company Name :"
ElseIf ((idx Mod 3) = 2) Then
Label1(idx).Text = "Designation :"
ElseIf ((idx Mod 3) = 0) Then
Label1(idx).Text = "Experience :"
End If
pnlCaption.Controls.Add(Label1(idx))
Next
End Sub

Public Function TotalExperience() As String

Dim companies, Experience, Designation As String
Dim Idx As Integer

For Idx = 1 To cboCompaniesWorkedIn.SelectedItem.Text
If Idx Mod 3 = 1 Then
companies = companies & textBox1(Idx).Text
End If
If Idx Mod 3 = 0 Then
Experience = Experience & textBox1(Idx).Text
End If
If Idx Mod 3 = 2 Then
companies = companies & textBox1(Idx).Text
End If
Next
End Function

Private Sub cmdLogOut1_Click(ByVal sender As System.Object, ByVal e
As System.Web.UI.ImageClickEventArgs) Handles cmdLogOut1.Click
Session("ResumeLogin") = ""
Response.Redirect("../frmAfterPost.aspx?MSG = Thanks For Taking
Time TO PostYour Resume. We Will Get Back In Touch With You Soon")
End Sub

Private Sub cmdClear1_Click(ByVal sender As System.Object, ByVal e
As System.Web.UI.ImageClickEventArgs) Handles cmdClear1.Click
cboCompaniesWorkedIn.SelectedIndex = 0
cboCourse.SelectedIndex = 0
cboProfCourse.SelectedIndex = 0
cboProfYearPassing.SelectedIndex = 0
cboYearPassing.SelectedIndex = 0
txtCertifications.Text = ""
txtCurrentSalary.Text = ""
txtInstitute.Text = ""
TxtProfInstitute.Text = ""
txtProfSpecilization.Text = ""
txtSpecilization.Text = ""
pnlCaption.Controls.Clear()
pnlText.Controls.Clear()
End Sub



Private Sub cmdSavenNext1_Click(ByVal sender As System.Object, ByVal
e As System.Web.UI.ImageClickEventArgs) Handles cmdSavenNext1.Click
If ValidatePage() Then
Exit Sub
End If
TotalExperience()
UpdateResume()
Response.Redirect("../frmAfterPost.aspx?MSG=Your Resume Has Been
Posted Successfully")
End Sub

Public Function ResumeExist() As Boolean
Try
Dim iSqlCommand As New SqlCommand()
Dim iSqlDataReader As SqlDataReader()
Dim sql, Exist As String

sql = "select Exist = case when email_address is null
then 'N' else 'Y' end from resume_master where email_address = '" &
Session("ResumeLogin") & "'"
iSqlConnection = iclsConnection.open(iSqlConnection)
iSqlCommand = New SqlCommand(sql, iSqlConnection)
Exist = iSqlCommand.ExecuteScalar()
If Exist = "Y" Then
ResumeExist = True
Else
ResumeExist = False
End If
Catch
ResumeExist = False
End Try
End Function

Public Function UpdateResume() As Boolean
Dim DoB As String
Dim iSqlCommand As New SqlCommand()
Dim sql, tmp As String
If iSqlConnection.State = ConnectionState.Closed Then
iSqlConnection = iclsConnection.open(iSqlConnection)
End If
tmp = UploadResume()
sql = "UPDATE [WhiteVisionSite].[dbo].[Resume_Master] " _
& " SET [Qualification]='" & cboCourse.SelectedItem.Text & "' ,
" _
& " [Specilization]= '" & txtSpecilization.Text & "', " _
& " [Institute]='" & txtInstitute.Text & "', " _
& " [Year_of_Passing]= '" & cboYearPassing.SelectedItem.Text &
"' , " _
& " [Professional_Qualification]='" &
cboProfCourse.SelectedItem.Text & "' , " _
& " [prof_Specilization]='" & txtProfSpecilization.Text & "', "
_
& " [Prof_Institute]= '" & TxtProfInstitute.Text & "', " _
& " [Prof_Year_Of_Passing]= '" &
cboProfYearPassing.SelectedItem.Text & "', " _
& " [Other_Qualification]= '" & txtCertifications.Text & "' , "
_
& " [Companies_Worked]= " &
cboCompaniesWorkedIn.SelectedItem.Text & " , " _
& " [Current_Salary]= " & txtCurrentSalary.Text & ", " _
& " [Detailed_Attached_Resume]= '" & tmp & "'" _
& " WHERE email_address = '" & Session("ResumeLogin") & "' "




iSqlCommand = New SqlCommand(sql, iSqlConnection)
iSqlCommand.ExecuteNonQuery()
'Dim sqlparam As New SqlParameter()
'sqlparam.Direction = ParameterDirection.Input
'sqlparam.ParameterName = "Detailed_Attached_Resume"
'sqlparam.DbType = SqlDbType.Image
'sqlparam.Value = UploadResume()
'iSqlCommand.Parameters.Add(sqlparam)


End Function

Public Function ValidatePage() As Boolean
Dim ExceptionString As String
Dim iclsUtility As New clsUtility()
If (cboCourse.SelectedIndex = 0) Then
ExceptionString = "* Please Select Date Of Qualification"
ValidatePage = True
End If
If (txtInstitute.Text = "") Then
ExceptionString = ExceptionString & "\n" & "* Please Enter
Institue"
ValidatePage = True
End If
If (txtCurrentSalary.Text = "") Or (Not
(IsNumeric(txtCurrentSalary.Text))) Then
ExceptionString = "* Please Enter Your Curent salary"
ValidatePage = True
End If
If ValidatePage = True Then
iclsUtility.ShowMessage(ExceptionString)
End If
End Function

Public Function UploadResume() As String
Dim FileName As String
Dim BR As BinaryReader
Dim Fs As FileStream
Dim tmp As String
Dim objstream As Stream
Dim INTLENGTH As Integer
Dim bytData() As Byte
Dim iconver As Convert

INTLENGTH = FilePath.PostedFile.ContentLength
ReDim bytData(INTLENGTH)
objstream = FilePath.PostedFile.InputStream
objstream.Read(bytData, 0, INTLENGTH)
tmp = Convert.ToBase64String(bytData)
Return tmp
' Dim iXmlReader As New XmlReader(objstream)
'Return iXmlReader

'Fs = New FileStream(FilePath.Value.ToString, FileMode.Open)
'BR = New BinaryReader(Fs)
'tmp = BR.ReadString

'UploadResume = tmp
End Function
End Class


Please See if You can Help me out.
Regards
Vivek
 
Back
Top