473,387 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

parameter:currentwebform to a vb class

Hello,
I'd like to use a visual basic class.function to iterate through the html
controls
and verify that the user entered something in the controls. But I cannot
figure out how to pass the current webform to the function.
Would anyone know how to do this?
I currently have this code in a function:
For Each child In c.Controls
If child.GetType.ToString = "System.web.ui.webcontrols.textbox" Then
txtbox = CType(child, TextBox)
' no blanks allowed.
If txtbox.Text.Equals("") Then
txtbox.BackColor = Color.Magenta
txtbox.Text = "required."
End If
End If

If child.GetType.ToString =
"System.web.ui.webcontrols.dropdownList" Then
ddl = CType(child, DropDownList)
' no blanks allowed.
If ddl.SelectedValue.Equals("") Then
ddl.BackColor = Magenta
End If
End If
Next
End If
Next

Thanks,

Feb 26 '07 #1
6 1182
bpd
On Feb 26, 3:55 pm, chieko <chi...@discussions.microsoft.comwrote:
Hello,
I'd like to use a visual basic class.function to iterate through the html
controls
and verify that the user entered something in the controls. But I cannot
figure out how to pass the current webform to the function.
Would anyone know how to do this?
I currently have this code in a function:
For Each child In c.Controls
If child.GetType.ToString = "System.web.ui.webcontrols.textbox" Then
txtbox = CType(child, TextBox)
' no blanks allowed.
If txtbox.Text.Equals("") Then
txtbox.BackColor = Color.Magenta
txtbox.Text = "required."
End If
End If

If child.GetType.ToString =
"System.web.ui.webcontrols.dropdownList" Then
ddl = CType(child, DropDownList)
' no blanks allowed.
If ddl.SelectedValue.Equals("") Then
ddl.BackColor = Magenta
End If
End If

Next
End If
Next

Thanks,

Why not just use the requiredFieldValidator on the controls?

Feb 26 '07 #2
bpd
On Feb 26, 3:55 pm, chieko <chi...@discussions.microsoft.comwrote:
Hello,
I'd like to use a visual basic class.function to iterate through the html
controls
and verify that the user entered something in the controls. But I cannot
figure out how to pass the current webform to the function.
Would anyone know how to do this?
I currently have this code in a function:
For Each child In c.Controls
If child.GetType.ToString = "System.web.ui.webcontrols.textbox" Then
txtbox = CType(child, TextBox)
' no blanks allowed.
If txtbox.Text.Equals("") Then
txtbox.BackColor = Color.Magenta
txtbox.Text = "required."
End If
End If

If child.GetType.ToString =
"System.web.ui.webcontrols.dropdownList" Then
ddl = CType(child, DropDownList)
' no blanks allowed.
If ddl.SelectedValue.Equals("") Then
ddl.BackColor = Magenta
End If
End If

Next
End If
Next

Thanks,

Why not just use the requiredFieldValidator on the controls?

Feb 26 '07 #3
BPD,
Because I have to do the same thing on 6 pages and I'm too lazy for gui's.
I'd rather call a function to do all the work for me.
Plus the function would be run on the server, not the client's machine.
Chieko

"bpd" wrote:
On Feb 26, 3:55 pm, chieko <chi...@discussions.microsoft.comwrote:
Hello,
I'd like to use a visual basic class.function to iterate through the html
controls
and verify that the user entered something in the controls. But I cannot
figure out how to pass the current webform to the function.
Would anyone know how to do this?
I currently have this code in a function:
For Each child In c.Controls
If child.GetType.ToString = "System.web.ui.webcontrols.textbox" Then
txtbox = CType(child, TextBox)
' no blanks allowed.
If txtbox.Text.Equals("") Then
txtbox.BackColor = Color.Magenta
txtbox.Text = "required."
End If
End If

If child.GetType.ToString =
"System.web.ui.webcontrols.dropdownList" Then
ddl = CType(child, DropDownList)
' no blanks allowed.
If ddl.SelectedValue.Equals("") Then
ddl.BackColor = Magenta
End If
End If

Next
End If
Next

Thanks,


Why not just use the requiredFieldValidator on the controls?

Feb 26 '07 #4
bpd
On Feb 26, 5:39 pm, chieko <chi...@discussions.microsoft.comwrote:
BPD,
Because I have to do the same thing on 6 pages and I'm too lazy for gui's.
I'd rather call a function to do all the work for me.
Plus the function would be run on the server, not the client's machine.
Chieko

"bpd" wrote:
On Feb 26, 3:55 pm, chieko <chi...@discussions.microsoft.comwrote:
Hello,
I'd like to use a visual basic class.function to iterate through the html
controls
and verify that the user entered something in the controls. But I cannot
figure out how to pass the current webform to the function.
Would anyone know how to do this?
I currently have this code in a function:
For Each child In c.Controls
If child.GetType.ToString = "System.web.ui.webcontrols.textbox" Then
txtbox = CType(child, TextBox)
' no blanks allowed.
If txtbox.Text.Equals("") Then
txtbox.BackColor = Color.Magenta
txtbox.Text = "required."
End If
End If
If child.GetType.ToString =
"System.web.ui.webcontrols.dropdownList" Then
ddl = CType(child, DropDownList)
' no blanks allowed.
If ddl.SelectedValue.Equals("") Then
ddl.BackColor = Magenta
End If
End If
Next
End If
Next
Thanks,
Why not just use the requiredFieldValidator on the controls?- Hide quoted text -

- Show quoted text -
Not sure, but you might be able to use Page.

protected void some_procedure()
{
if (process_page_procedure(Page))
{
do something...
}
}

static bool process_page_procedure(Page p)
{
do something with p.Form.Controls
}

Feb 27 '07 #5
Thanks,
I'll give it a try.
Chieko

"bpd" wrote:
On Feb 26, 5:39 pm, chieko <chi...@discussions.microsoft.comwrote:
BPD,
Because I have to do the same thing on 6 pages and I'm too lazy for gui's.
I'd rather call a function to do all the work for me.
Plus the function would be run on the server, not the client's machine.
Chieko

"bpd" wrote:
On Feb 26, 3:55 pm, chieko <chi...@discussions.microsoft.comwrote:
Hello,
I'd like to use a visual basic class.function to iterate through the html
controls
and verify that the user entered something in the controls. But I cannot
figure out how to pass the current webform to the function.
Would anyone know how to do this?
I currently have this code in a function:
For Each child In c.Controls
If child.GetType.ToString = "System.web.ui.webcontrols.textbox" Then
txtbox = CType(child, TextBox)
' no blanks allowed.
If txtbox.Text.Equals("") Then
txtbox.BackColor = Color.Magenta
txtbox.Text = "required."
End If
End If
If child.GetType.ToString =
"System.web.ui.webcontrols.dropdownList" Then
ddl = CType(child, DropDownList)
' no blanks allowed.
If ddl.SelectedValue.Equals("") Then
ddl.BackColor = Magenta
End If
End If
Next
End If
Next
Thanks,
Why not just use the requiredFieldValidator on the controls?- Hide quoted text -
- Show quoted text -

Not sure, but you might be able to use Page.

protected void some_procedure()
{
if (process_page_procedure(Page))
{
do something...
}
}

static bool process_page_procedure(Page p)
{
do something with p.Form.Controls
}

Feb 28 '07 #6
Here's the whole function that you can call from the code behind in the
xxx.aspx.vb page:

In a vb class write a function similar to this:

Public Function SetWebControls(ByRef webpage As System.Web.UI.Page) As Boolean
Dim bRet As Boolean = True
Dim d As System.Web.UI.Control
Dim dChild As System.Web.UI.Control
Dim txtbox As System.Web.UI.WebControls.TextBox

Dim ddlDropDownList1 As System.Web.UI.WebControls.DropDownList
Dim ddlDropDownList2 As System.Web.UI.WebControls.DropDownList
Dim ddlDropDownList3 As System.Web.UI.WebControls.DropDownList

Dim type As String 'for debugging
Dim type2 As String ' for debugging
Dim textboxname As String ' for debugging.
Dim dsStates As New DataSet
Dim dsCountries As New DataSet
Dim dsSecurityQuestions As SqlClient.SqlDataReader

Dim security As New ISEERegistrationBusiness.Security.Security
Dim i As Integer 'counter

For Each d In webpage.Controls
If d.Controls.Count 0 And d.GetType.ToString = _
"System.Web.UI.HtmlControls.HtmlForm" Then
type2 = (d.GetType.ToString) ' for debugging
For Each dChild In d.Controls
' set the textboxes
If dChild.GetType.ToString = "System.Web.UI.WebControls.TextBox"
Then
txtbox = CType(dChild, System.Web.UI.WebControls.TextBox)
txtbox.Text = "required"
txtbox.MaxLength = 40
End If
' set the drop down list : ddlDropDownList1
If dChild.GetType.ToString =
"System.Web.UI.WebControls.DropDownList" Then
If dChild.ID.ToString = "ddlDropDownList1" Then
ddlDropDownList1 = CType(dChild, System.Web.UI.WebControls.DropDownList)

' do something ie: For i = 0 To
dsStates.tables(0).rows.Count - 1
ddlDropDownList1.Items.Add(New
System.Web.UI.WebControls.ListItem(dsStates.Tables (0).Rows(i).Item("State")))
Next
End If
End If

' set the drop down list : ddlDropDownlist2
If dChild.ID.ToString = "ddlDropDownlist2" Then
ddlDropDownList2 = CType(dChild,
System.Web.UI.WebControls.DropDownList)
' doSomething like :
For i = 0 To dsCountries.Tables(0).Rows.Count - 1
ddlDropDownList2.Items.Add(New
System.Web.UI.WebControls.ListItem(dsCountries.Tab les(0).Rows(i).Item(0)))
Next
End If
End If

'set the drop down list : ddlDropDownList3
If dChild.ID.ToString = "ddlDropDownList3" Then
ddlDropDownList3 = CType(dChild,
System.Web.UI.WebControls.DropDownList)
'Do something like:
While dsSecurityQuestions.Read

ddlDropDownList3.Items.Add(dsSecurityQuestions.Ite m("securityQuestionID") & "
" & dsSecurityQuestions.Item("securityQuestion"))
End While
End If
End If

End If
Next
End If
Next
return bRet
End Function

' call the function from the xxx.aspx.vp page.
If not SetWebControls(Me) then
response.Write "Page could not be loaded."
End If
Mar 1 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mysooru | last post by:
Hi All, One of the ATL class..... template <class Base> class CComObject : public Base { public: typedef Base _BaseClass;
3
by: SimonH | last post by:
Hi all, I would like to make a generic set of methods that could be called regardless of the database behind the scenes. One of the methods I would like would take a string sql statement and...
7
by: ThazKool | last post by:
Is there an elegant/efficient way to use a typedef of a class passed in to a template parameter. I know that a second template parameter can be given, but I was wondering if there is any way to...
2
by: Siegfried Weiss | last post by:
Hi guys, i give up finding a solution by reading or by trial & error. Hope, YOU can help me! (Sorry for my rather long posting.) Stroustrup says, that templates could be declared with - type...
1
by: Adam Getchell | last post by:
Hello all, I'm writing a Parameter class (following Fowler's "Introduce Parameter Object") that accepts a stored procedure and key-value pairs to be passed to a data access class that will parse...
0
by: Greg Merideth | last post by:
I ran into a small snag in passing in a class as a parameter to a web method from our calling code. Now, we routinely pass *back* as a return value from a method, a class reference and that...
3
by: pauldepstein | last post by:
Sorry in advance if this message sounds imprecise but it's difficult to be precise when you don't really understand what's going on. I have a class called Parameters. The default constructor...
4
by: huguogang | last post by:
Just curious, any one know what the 3 part parameter "class CString filename" would mean. The code: int TestFunc(class CString filename) { fopen(filename, "w"); } Compile using Visaul C++,...
7
by: Andy B | last post by:
I have a class I am creating for data access. I need to access controls from inside the class that are on a particular page. How do I do this? or is creating an instance of the page class and using...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.