problems with modules

J

Jose Meireles

Hi everyone

I've created a module (in a web app) to hold several generic functions as
subroutines. The problem I face is that I've got problems with the call of
system functions with wich I don't have problems if creating the same
function within the webform class.

as an example here follows a soubroutine within a module

Imports System.Web.UI

Public Class geralMdl

Shared Function LimparTexto(ByVal IdForm As String) As Boolean

Dim Form As Control = FindControl(IdForm)

If IsNothing(Form) Then

LimparTexto = False

Else

LimparTexto = True

Dim Control As Control

For Each Control In Form.Controls

If TypeOf Control Is WebControls.TextBox Then

CType(Control, WebControls.TextBox).Text = ""

End If

Next

Control = Nothing

End If

Form = Nothing

End Function

End Class

The function findControl is not recognized.....!!!! in the task list it says
that it's not declared....

Does anyone can help me with this?

thanks

JM
 
R

rs_tiin

Hi

FindControl is a function of the PagClass. As all ASPX
pages inherit from the Page Class, it would have worked
in ur web form properly. now if u are writin g a separate
Class for generic purposes, then wat u can do is

a) make the LimparTexto accept a parameter of page class
i.e. Shared Function LimparTexto(l_objPage as Page, ByVal
IdForm As String) As Boolean


b) Pass the Web Page(if LimparTexto function is called
from a web page then u can pass Me) as a parameter to the
LimparTexto function
c) Instead of
Dim Form As Control = FindControl(IdForm)
use
Dim Form As Control = l_objPage.FindControl(IdForm)

hth

regards,

sr
 
J

Jose Meireles

It works in perfection.

Thanks SR

JM
Hi

FindControl is a function of the PagClass. As all ASPX
pages inherit from the Page Class, it would have worked
in ur web form properly. now if u are writin g a separate
Class for generic purposes, then wat u can do is

a) make the LimparTexto accept a parameter of page class
i.e. Shared Function LimparTexto(l_objPage as Page, ByVal
IdForm As String) As Boolean


b) Pass the Web Page(if LimparTexto function is called
from a web page then u can pass Me) as a parameter to the
LimparTexto function
c) Instead of
Dim Form As Control = FindControl(IdForm)
use
Dim Form As Control = l_objPage.FindControl(IdForm)

hth

regards,

sr
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top