problems with modules

  • Thread starter Thread starter Jose Meireles
  • Start date Start date
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
 
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
 
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
 
Back
Top