473,803 Members | 2,972 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dumb Question About External References


Hello everyone,

I'm new to C# and ASP.NET, so pardon my stupidity on this one.

I'm having a problem with referencing methods/functions external
to a class member function.

My code is as follows:
. . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . .
/* - - - - - - - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - - - - - - - */
public class ccp_01 : base_create_ctr l_pair
{
public ccp_01 (ControlCollect ion pram_ph01_ctrl)
: base (pram_ph01_ctrl ) {}
//{ base_create_ctr l_pair (pram_ph01_ctrl ); }

public void create_ctrl_pai r_01 ()
{ create_ctrl_pai r_0x
("UserTextBox1" , "DButton01" , "Submit 01");

button0x.Click += new EventHandler (Submit_Click);

if (!Page.IsPostBa ck)
init_single_lin e_text_box (UserTextBox0x, 22);

ph01_ctrl.Add ( new LiteralControl( "<br><br>") );
}
}
/* - - - - - - - - - - - - - - - - - - - - - - */

. . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . .

/* -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- */
public void Submit_Click(Ob ject sender, EventArgs e)
{ // Retrieve the UserTextBox TextBox control from the TextBoxControlP laceHolder
// PlaceHolder control.

TextBox TempTextBox
= (TextBox)TextBo xControlPlaceHo lder.FindContro l("UserTextBox1 ");

// Display the Text property.
Message.Text
= submit_click_st r01 + '1' + submit_click_st r02 + TempTextBox.Tex t;
}
. . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . .

The compiler issues diagnostics, and they are as follows
(with the offending lines in square brackets):
. . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . .

C:\WINNT\system 32> "c:\winnt\micro soft.net\framew ork\v1.1.4322\c sc.exe"
/t:library /utf8output
/R:"c:\winnt\ass embly\gac\syste m.enterpriseser vices\1.0.5000. 0__b03f5f7f11d5 0a3a
\system.enterpr iseservices.dll "
/R:"c:\winnt\ass embly\gac\syste m.data\1.0.5000 .0__b77a5c56193 4e089\system.da ta.dll"

/R:"c:\winnt\ass embly\gac\syste m.drawing\1.0.5 000.0__b03f5f7f 11d50a3a\system .drawing.dll"

/R:"c:\winnt\ass embly\gac\syste m.web.mobile\1. 0.5000.0__b03f5 f7f11d50a3a\sys tem.web.mobile. dll"
/R:"c:\winnt\ass embly\gac\syste m.xml\1.0.5000. 0__b77a5c561934 e089\system.xml .dll"

/R:"c:\winnt\ass embly\gac\syste m.web.services\ 1.0.5000.0__b03 f5f7f11d50a3a\s ystem.web.servi ces.dll"
/R:"c:\winnt\ass embly\gac\syste m\1.0.5000.0__b 77a5c561934e089 \system.dll"
/R:"c:\winnt\ass embly\gac\syste m.web\1.0.5000. 0__b03f5f7f11d5 0a3a\system.web .dll"
/R:"c:\winnt\mic rosoft.net\fram ework\v1.1.4322 \mscorlib.dll"
/out:"C:\WINNT\M icrosoft.NET\Fr amework\v1.1.43 22\Temporary ASP.NET Files

\webfolder01\08 460e05\9c82db3e \rdoqxnq-.dll"
/debug- /optimize+ /warnaserror
/w:1 "C:\WINNT\Micro soft.NET\Framew ork\v1.1.4322\T emporary ASP.NET Files

\webfolder01\08 460e05\9c82db3e \rdoqxnq-.0.cs"
Microsoft (R) Visual C# .NET Compiler version 7.10.6001.4
for Microsoft (R) .NET Framework version 1.1.4322
Copyright (C) Microsoft Corporation 2001-2002. All rights reserved.

I:\Virtual Webfolders\View State02.aspx(12 3,50): error CS0038:
Cannot access a nonstatic member of outer type 'ASP.ViewState0 2_aspx'
via nested type 'ASP.ViewState0 2_aspx.ccp_01'

[button0x.Click += new EventHandler (Submit_Click);]
I:\Virtual Webfolders\View State02.aspx(12 5,19): error CS0120:
An object reference is required for the nonstatic field, method,
or property 'System.Web.UI. Page.IsPostBack '

[if (!Page.IsPostBa ck)]

. . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . .

This is probably a piece of cake for most of you.

Can anyone clue me in as to what I need to do to make the external references?

Thanks In Advance.

- wASP
Nov 17 '05 #1
6 2489
> I'm having a problem with referencing methods/functions external
to a class member function.

It looks like you're calling System.Web.Ui.P age members outside the Page
class. The ccp_01 class doesn't have a IsPostback member!

A solution can be to pass a Page object to the constructor of the ccp_01
class.

If you post your entire ASPX page, I'll see if I can get an example.

Greetings,
Wessel
Nov 17 '05 #2
On Tue, 26 Jul 2005 14:07:48 +0200, "Wessel Troost" <no*****@like.t he.sun> wrote:
I'm having a problem with referencing methods/functions external
to a class member function.

It looks like you're calling System.Web.Ui.P age members outside the Page
class. The ccp_01 class doesn't have a IsPostback member!

A solution can be to pass a Page object to the constructor of the ccp_01
class.

If you post your entire ASPX page, I'll see if I can get an example.

Greetings,
Wessel


Hi Wessel,

Here's the whole thing (it's just a toy for my own enlightenment):
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
<%@ Page Language="C#" AutoEventWireup ="True" %>

<html>
<head>

<script runat="server">

/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
String submit_click_st r01 = "The TextBox";

String submit_click_st r02
= " control above is dynamically generated. <br> You entered: ";
/* -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- */
public void Submit_Click(Ob ject sender, EventArgs e)
{ TextBox TempTextBox =
(TextBox)TextBo xControlPlaceHo lder.FindContro l("UserTextBox1 ");
Message.Text = submit_click_st r01 + '1' + submit_click_st r02 +
TempTextBox.Tex t;
}

protected void Submit_Click2(O bject sender, EventArgs e)
{ TextBox TempTextBox =
(TextBox)TextBo xControlPlaceHo lder.FindContro l("UserTextBox2 ");
Message.Text = submit_click_st r01 + '2' + submit_click_st r02 +
TempTextBox.Tex t;
}

protected void Submit_Click3(O bject sender, EventArgs e)
{ TextBox TempTextBox =
(TextBox)TextBo xControlPlaceHo lder.FindContro l("UserTextBox3 ");
Message.Text = submit_click_st r01 + '3' + submit_click_st r02 +
TempTextBox.Tex t;
}
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
protected void Page_Load(Objec t sender, EventArgs e)
{
ControlCollecti on pram_ph01_ctrl = TextBoxControlP laceHolder.Cont rols;

ccp_01 ccp1 = new ccp_01 (pram_ph01_ctrl );
ccp_02 ccp2 = new ccp_02 (pram_ph01_ctrl );
ccp_03 ccp3 = new ccp_03 (pram_ph01_ctrl );

ccp1.create_ctr l_pair_01 ();
ccp2.create_ctr l_pair_02 ();
ccp3.create_ctr l_pair_03 ();
}
/* - - - - - - - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - - - - - - - */
public class base_create_ctr l_pair
{
protected TextBox UserTextBox0x;
protected Button button0x;
protected ControlCollecti on ph01_ctrl;

// constructor
protected base_create_ctr l_pair (ControlCollect ion pram_ph01_ctrl)
{ ph01_ctrl = pram_ph01_ctrl; }

/* . . . . . . . . . . . . . . . */
public TextBox create_text_box _control (String text_box_id)
{ // Create UserTextBox TextBox control.
TextBox new_TextBox = new TextBox ();

// Configure the UserTextBox TextBox control.
new_TextBox.ID = text_box_id;

// Add UserTextBox TextBox control to the Controls collection
// of the TextBoxControlP laceHolder PlaceHolder control.
ph01_ctrl.Add (new_TextBox);

return new_TextBox;
}
/* . . . . . . . . . . . . . . . */

/* --------------------------------------------------------- */
/* --------------------------------------------------------- */
protected void InitializeMyBut ton (String Btn_ID, String Btn_text)
{ // Create and initialize a Button.
button0x = new Button();
ph01_ctrl.Add (button0x);

button0x.ID = Btn_ID;
button0x.Text = Btn_text;

ph01_ctrl.Add ( new LiteralControl( "<br><br>") );
}

protected void init_single_lin e_text_box (TextBox new_TextBox, int col_sz)
{ new_TextBox.Col umns = col_sz; }

protected void create_ctrl_pai r_0x
(String TB_ID, String DB_ID, String DB_txt)
{ // Create UserTextBox TextBox control.
UserTextBox0x = create_text_box _control (TB_ID);
InitializeMyBut ton (DB_ID, DB_txt);
}
} /* END: public class base_create_ctr l_pair */
/* - - - - - - - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - - - - - - - */

/* - - - - - - - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - - - - - - - */
public class ccp_01 : base_create_ctr l_pair
{
// constructor
public ccp_01 (ControlCollect ion pram_ph01_ctrl)
: base (pram_ph01_ctrl ) {}

public void create_ctrl_pai r_01 ()
{ create_ctrl_pai r_0x
("UserTextBox1" , "DButton01" , "Submit 01");

button0x.Click += new EventHandler (Submit_Click);

if (!Page.IsPostBa ck)
init_single_lin e_text_box (UserTextBox0x, 22);

ph01_ctrl.Add ( new LiteralControl( "<br><br>") );
}
}
/* - - - - - - - - - - - - - - - - - - - - - - */
public class ccp_02 : base_create_ctr l_pair
{
public ccp_02 (ControlCollect ion pram_ph01_ctrl)
: base (pram_ph01_ctrl ) {}

public void create_ctrl_pai r_02 ()
{ // Create UserTextBox TextBox control.
create_ctrl_pai r_0x
("UserTextBox2" , "DButton02" , "Submit 02");

button0x.Click += new EventHandler (Submit_Click2) ;

if (!Page.IsPostBa ck)
init_single_lin e_text_box (UserTextBox0x, 22);

ph01_ctrl.Add ( new LiteralControl( "<br><br>") );
}
}
/* - - - - - - - - - - - - - - - - - - - - - - */
public class ccp_03 : base_create_ctr l_pair
{
public ccp_03 (ControlCollect ion pram_ph01_ctrl)
: base (pram_ph01_ctrl ) {}

public void create_ctrl_pai r_03 ()
{ // Create UserTextBox TextBox control.
create_ctrl_pai r_0x
("UserTextBox3" , "DButton03" , "Submit 03");

button0x.Click += new EventHandler (Submit_Click3) ;

if (!Page.IsPostBa ck)
init_single_lin e_text_box (UserTextBox0x, 22);

ph01_ctrl.Add ( new LiteralControl( "<br><br>") );
}
}
/* - - - - - - - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - - - - - - - */

</script>
</head>

<body>

<form runat="server">

<h3> TextBox Constructor Example </h3>

Enter some text and click the Submit button. <br><br>

<asp:PlaceHolde r ID="TextBoxCont rolPlaceHolder" runat="server"/>

<asp:Label ID="Message" runat="server"/>

</form>

</body>
</html>
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\

What follows are the diagnostics:
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\

Microsoft (R) Visual C# .NET Compiler version 7.10.6001.4
for Microsoft (R) .NET Framework version 1.1.4322
Copyright (C) Microsoft Corporation 2001-2002. All rights reserved.

I:\Virtual Webfolders\Clea n\ViewState02.a spx(109,52): error CS0038:
Cannot access a nonstatic member of outer type 'ASP.ViewState0 2_aspx'
via nested type 'ASP.ViewState0 2_aspx.ccp_01'

I:\Virtual Webfolders\Clea n\ViewState02.a spx(111,21): error CS0120:
An object reference is required for the nonstatic field, method,
or property 'System.Web.UI. Page.IsPostBack '

I:\Virtual Webfolders\Clea n\ViewState02.a spx(128,50): error CS0038:
Cannot access a nonstatic member of outer type 'ASP.ViewState0 2_aspx'
via nested type 'ASP.ViewState0 2_aspx.ccp_02'

I:\Virtual Webfolders\Clea n\ViewState02.a spx(130,19): error CS0120:
An object reference is required for the nonstatic field, method,
or property 'System.Web.UI. Page.IsPostBack '

I:\Virtual Webfolders\Clea n\ViewState02.a spx(147,50): error CS0038:
Cannot access a nonstatic member of outer type 'ASP.ViewState0 2_aspx'
via nested type 'ASP.ViewState0 2_aspx.ccp_03'

I:\Virtual Webfolders\Clea n\ViewState02.a spx(149,19): error CS0120:
An object reference is required for the nonstatic field, method,
or property 'System.Web.UI. Page.IsPostBack '

//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\

What baffles me is that, if the compiler can make reference to the IsPostBack member,
and recognise it as being in the proper namespace ...
- - - - - - - - - - - - - - - - - - - - - - - -
An object reference is required for the nonstatic field, method,
or property 'System.Web.UI. Page.IsPostBack '
- - - - - - - - - - - - - - - - - - - - - - - -

... then why can't it resolve the reference?
Maybe I need to break down and go buy a good reference for C#,
instead of trying to rely upon my C++ background - and glean what I can
from the MS docs and various websites/forums.

Does anyone have any recomendations?

- wASP
Nov 17 '05 #3
> What baffles me is that, if the compiler can make reference to the
IsPostBack member,
and recognise it as being in the proper namespace ...
- - - - - - - - - - - - - - - - - - - - - - - -
An object reference is required for the nonstatic field, method,
or property 'System.Web.UI. Page.IsPostBack '
- - - - - - - - - - - - - - - - - - - - - - - -

... then why can't it resolve the reference?
The namespace is correct, but there is no object. An object is an
instance of a class. Your code is the C++ equivalent of (uncompiled code):

class Class
{
void Method();
}

int main()
{
// This doesn't work; nonstatic method needs an object, not a class
Class.Method();
// This will work; we have an instance of the class to call
Class TheObject();
TheObject.Metho d();
return 0;
}
Maybe I need to break down and go buy a good reference for C#,
instead of trying to rely upon my C++ background - and glean what I can
from the MS docs and various websites/forums.
Well yeah, and you could use a better coding style, if you''ll pardon me.
pram_ph01_ctrl doesn't tell me much about what the variable does.
Consider arrTextControls or m_TextControls or TextControls?
Does anyone have any recomendations?

Take a subscription on Safari (http://oreilly.safari.com) which allows you
to scan books and only read the ones that are really good. Way cheaper
than buying real books :)

Working sample follows.

Greetings,
Wessel

<%@ Page Language="C#" AutoEventWireup ="True" %>

<html>
<head>

<script runat="server">

/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
String submit_click_st r01 = "The TextBox";

String submit_click_st r02
= " control above is dynamically generated. <br> You entered: ";
/*
-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- */
public void Submit_Click(Ob ject sender, EventArgs e)
{ TextBox TempTextBox =
(TextBox)TextBo xControlPlaceHo lder.FindContro l("UserTextBox1 ");
Message.Text = submit_click_st r01 + '1' + submit_click_st r02 +
TempTextBox.Tex t;
}

protected void Submit_Click2(O bject sender, EventArgs e)
{ TextBox TempTextBox =
(TextBox)TextBo xControlPlaceHo lder.FindContro l("UserTextBox2 ");
Message.Text = submit_click_st r01 + '2' + submit_click_st r02 +
TempTextBox.Tex t;
}

protected void Submit_Click3(O bject sender, EventArgs e)
{ TextBox TempTextBox =
(TextBox)TextBo xControlPlaceHo lder.FindContro l("UserTextBox3 ");
Message.Text = submit_click_st r01 + '3' + submit_click_st r02 +
TempTextBox.Tex t;
}
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
protected void Page_Load(Objec t sender, EventArgs e)
{
ControlCollecti on pram_ph01_ctrl =
TextBoxControlP laceHolder.Cont rols;

ccp_01 ccp1 = new ccp_01(pram_ph0 1_ctrl);
ccp_02 ccp2 = new ccp_02(pram_ph0 1_ctrl);
ccp_03 ccp3 = new ccp_03(pram_ph0 1_ctrl);

ccp1.create_ctr l_pair_01(new EventHandler(Su bmit_Click),
this.IsPostBack );
ccp2.create_ctr l_pair_02(new EventHandler(Su bmit_Click2),
this.IsPostBack );
ccp3.create_ctr l_pair_03(new EventHandler(Su bmit_Click3),
this.IsPostBack );
}
/* - - - - - - - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - - - - - - - */
public class base_create_ctr l_pair
{
protected TextBox UserTextBox0x;
protected Button button0x;
protected ControlCollecti on ph01_ctrl;

// constructor
protected base_create_ctr l_pair (ControlCollect ion
pram_ph01_ctrl)
{ ph01_ctrl = pram_ph01_ctrl; }

/* . . . . . . . . . . . . . . . */
public TextBox create_text_box _control (String text_box_id)
{ // Create UserTextBox TextBox control.
TextBox new_TextBox = new TextBox ();

// Configure the UserTextBox TextBox control.
new_TextBox.ID = text_box_id;

// Add UserTextBox TextBox control to the Controls collection
// of the TextBoxControlP laceHolder PlaceHolder control.
ph01_ctrl.Add (new_TextBox);

return new_TextBox;
}
/* . . . . . . . . . . . . . . . */

/* --------------------------------------------------------- */
/* --------------------------------------------------------- */
protected void InitializeMyBut ton (String Btn_ID, String
Btn_text)
{ // Create and initialize a Button.
button0x = new Button();
ph01_ctrl.Add (button0x);

button0x.ID = Btn_ID;
button0x.Text = Btn_text;

ph01_ctrl.Add ( new LiteralControl( "<br><br>") );
}

protected void init_single_lin e_text_box (TextBox new_TextBox,
int col_sz)
{ new_TextBox.Col umns = col_sz; }

protected void create_ctrl_pai r_0x
(String TB_ID, String DB_ID, String DB_txt)
{ // Create UserTextBox TextBox control.
UserTextBox0x = create_text_box _control (TB_ID);
InitializeMyBut ton (DB_ID, DB_txt);
}
} /* END: public class base_create_ctr l_pair */
/* - - - - - - - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - - - - - - - */

/* - - - - - - - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - - - - - - - */
public class ccp_01 : base_create_ctr l_pair
{
// constructor
public ccp_01 (ControlCollect ion pram_ph01_ctrl )
: base (pram_ph01_ctrl ) {}

public void create_ctrl_pai r_01 ( EventHandler oEventHandler,
bool bIsPostback )
{ create_ctrl_pai r_0x
("UserTextBox1" , "DButton01" , "Submit 01");

button0x.Click += oEventHandler;

if (!bIsPostback)
init_single_lin e_text_box (UserTextBox0x, 22);

ph01_ctrl.Add ( new LiteralControl( "<br><br>") );
}
}
/* - - - - - - - - - - - - - - - - - - - - - - */
public class ccp_02 : base_create_ctr l_pair
{
public ccp_02 (ControlCollect ion pram_ph01_ctrl)
: base (pram_ph01_ctrl ) {}

public void create_ctrl_pai r_02 ( EventHandler oEventHandler,
bool bIsPostBack )
{ // Create UserTextBox TextBox control.
create_ctrl_pai r_0x
("UserTextBox2" , "DButton02" , "Submit 02");

button0x.Click += oEventHandler;

if (!bIsPostBack)
init_single_lin e_text_box (UserTextBox0x, 22);

ph01_ctrl.Add ( new LiteralControl( "<br><br>") );
}
}
/* - - - - - - - - - - - - - - - - - - - - - - */
public class ccp_03 : base_create_ctr l_pair
{
public ccp_03 (ControlCollect ion pram_ph01_ctrl)
: base (pram_ph01_ctrl ) {}

public void create_ctrl_pai r_03(EventHandl er oEventHandler, bool
bIsPostBack)
{ // Create UserTextBox TextBox control.
create_ctrl_pai r_0x
("UserTextBox3" , "DButton03" , "Submit 03");

button0x.Click += oEventHandler;

if (!bIsPostBack)
init_single_lin e_text_box (UserTextBox0x, 22);

ph01_ctrl.Add ( new LiteralControl( "<br><br>") );
}
}
/* - - - - - - - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - - - - - - - */

</script>
</head>

<body>

<form id="Form1" runat="server">

<h3> TextBox Constructor Example </h3>

Enter some text and click the Submit button. <br><br>

<asp:PlaceHolde r ID="TextBoxCont rolPlaceHolder" runat="server"/>

<asp:Label ID="Message" runat="server"/>

</form>

</body>
</html>
Nov 17 '05 #4
On Tue, 26 Jul 2005 22:21:53 +0200, "Wessel Troost" <no*****@like.t he.sun> wrote:
What baffles me is that, if the compiler can make reference to the
IsPostBack member,
and recognise it as being in the proper namespace ...
- - - - - - - - - - - - - - - - - - - - - - - -
An object reference is required for the nonstatic field, method,
or property 'System.Web.UI. Page.IsPostBack '
- - - - - - - - - - - - - - - - - - - - - - - -

... then why can't it resolve the reference?
The namespace is correct, but there is no object. An object is an
instance of a class. Your code is the C++ equivalent of (uncompiled code):

class Class
{
void Method();
}

int main()
{
// This doesn't work; nonstatic method needs an object, not a class
Class.Method();
// This will work; we have an instance of the class to call
Class TheObject();
TheObject.Metho d();
return 0;
}


I understand this, but it's my understanding that a Page object is created
automatically whenever the request is put to the server for the webpage
- so there should be a page object already instantiated.

On top of that, the Page.IsPostBack works OK when in the Page_Load function,
so that proves that SOMETHING is "there" - I just cannot figure out how
to reference it in a class method/function as of yet.

C# isn't as easy to figure out as the books make it out to be.

Maybe I need to break down and go buy a good reference for C#,
instead of trying to rely upon my C++ background - and glean what I can
from the MS docs and various websites/forums.

Well yeah, and you could use a better coding style, if you''ll pardon me.


I normally do.

REMEMBER: This is just a TOY - not something intended as an end-product.

pram_ph01_ct rl doesn't tell me much about what the variable does.
Consider arrTextControls or m_TextControls or TextControls?
I normally use VERY long variable/reference names - I just didn't do it in
the cases that you're refering to - sorry - I should have used search & substitute
to give those symbols more descriptive names before posting it - my appologies
to you and to anyone else who is reading this. I was just in a hurry to get it posted
- so I can get this problem resolved - and move on to the next problem.

Does anyone have any recomendations?

Take a subscription on Safari (http://oreilly.safari.com) which allows you
to scan books and only read the ones that are really good. Way cheaper
than buying real books :)


DAMMIT! Too late to tell me that - I made a quick trip to Barnes & Nobles
this afternoon to grab a few books - I couldn't wait for a response that
might or might not come.

OTOH: I suppose there's no reason why I couldn't go ahead and subscribe anyway
- it would give me more sources to draw from - and you can never have too many.

Sooooo - THANKS!

Working sample follows.


I appreciate the effort - and I have saved it to my forum message folder
(it will be there throughout all eternity as I never delete anything)
- but it doesn't really answer my original question:
How do I invoke those functions/clases/methods within the class methods
without having to pass references as parameters in the arglist?

REMEMBER: This is just a TOY - I'm not really trying to solve specific problems
related to the functioning of my little toy - but to resolve the basic issues
that this toy might raise - and HAS raised. I know that I never did have
this kind of a problem with C++.

Can you tell that this is frustrating the HELL out of me?

... well it IS!
I've been reading my books, and I'll make another post after I get a bit better
educated on this matter. Stay tuned for further developments ...
Thanks Wessel!
- wASP
Nov 17 '05 #5
> On top of that, the Page.IsPostBack works OK when in the Page_Load
function,
so that proves that SOMETHING is "there" - I just cannot figure out how
to reference it in a class method/function as of yet.
That must be the source of the confusion. Page_Load is actually a member
function of the Page class, so it has access to the page class. But if
you define a new class, it has no relation to the Page class, even though
it is declared inside the page.

You can't just call IsPostback from anywhere; it has to be from inside the
Page object, or using a reference to the page object.
How do I invoke those functions/clases/methods within the class methods
without having to pass references as parameters in the arglist?

From a class member, just call:
IsPostback()
or:
this.IsPostback ()

From a class that is unrelated, you have to call:
System.Web.UI.P age ThePage = ...;
ThePage.IsPostb ack()

Greetings,
Wessel
Nov 17 '05 #6
On Wed, 27 Jul 2005 09:24:48 +0200, "Wessel Troost" <no*****@like.t he.sun> wrote:
On top of that, the Page.IsPostBack works OK when in the Page_Load
function,
so that proves that SOMETHING is "there" - I just cannot figure out how
to reference it in a class method/function as of yet.

That must be the source of the confusion. Page_Load is actually a member
function of the Page class, so it has access to the page class. But if
you define a new class, it has no relation to the Page class, even though
it is declared inside the page.

You can't just call IsPostback from anywhere; it has to be from inside the
Page object, or using a reference to the page object.


Golly geeeeeee whizzzz - I did not know that
- and I'm NOT being sarcastic when I tell you that
- so don't take it that way.

I did not know that - seriously.

For some strange reason, I thought that the page object was global to
anything and everything on the page - so this comes as a bit of a stunner.
A big part of my problem in all of this is that I don't have a firm understanding
of the nature of scoping in C# - but now you've given me a clue about it.

Has anyone told you that you're wonderful, Wessel?

Well I'll tell you: You're wonderful, Wessel.

How do I invoke those functions/clases/methods within the class methods
without having to pass references as parameters in the arglist?

From a class member, just call:
IsPostback()
or:
this.IsPostback ()

From a class that is unrelated, you have to call:
System.Web.UI.P age ThePage = ...;
ThePage.IsPostb ack()


Yes, but my problem is with the ellipsis - those 3 dots after “ThePage.”

In any case, after I read your most recent post on this matter,
and become better enlightened, I’ve been re-engineering my little toy
- and I’ve gotten the latest version of it to work:
/-\_/-\_/-\_/-\_/-\_/-\_/-\_/-\_/-\_/-\_/-\_/-\_/-\_/-\_/-\_/-\_/-\
\_/-\_/-\_/-\_/-\_/-\_/-\_/-\_/-\_/-\_/-\_/-\_/-\_/-\_/-\_/-\_/-\-/

<%@ Page Language="C#" AutoEventWireup ="True" %>

<html>
<head>

<script runat="server">

/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */

/* -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- */
// protected class sys_obj_class
public class sys_obj_class
{
private ControlCollecti on pram_ph01_ctrl;
public ControlCollecti on Get_pram_ph01_c trl
{ get { return pram_ph01_ctrl; } }

private Page this_page01;
public Page Get_this_page01
{ get { return this_page01; } }

private PlaceHolder Obj_Dyn_Ctrl_Pl aceholder;
public PlaceHolder Get_Obj_Dyn_Ctr l_Placeholder
{ get { return Obj_Dyn_Ctrl_Pl aceholder; } }

private Label Obj_Dyn_Label01 ;
public Label Get_Obj_Dyn_Lab el01
{ get { return Obj_Dyn_Label01 ; } }
public sys_obj_class
(PlaceHolder Dyn_Ctrl_Placeh older, Label Dyn_Label)
{ pram_ph01_ctrl = Dyn_Ctrl_Placeh older.Controls;
this_page01 = Dyn_Ctrl_Placeh older.Page;
Obj_Dyn_Ctrl_Pl aceholder = Dyn_Ctrl_Placeh older;
Obj_Dyn_Label01 = Dyn_Label;
}
}

/* -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- */
/* public static void Submit_Click (Object sender, EventArgs e) */
/* -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- */

/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
protected void Page_Load (Object sender, EventArgs e)
{
PlaceHolder plc_hldr = (PlaceHolder) FindControl ("Dyn_Control_P laceholder");
Label lbl_msg01 = (Label) FindControl ("Message01" );
sys_obj_class sys_obj = new sys_obj_class (plc_hldr, lbl_msg01);

ctrl_pair_creat ion_01 ccp1 = new ctrl_pair_creat ion_01 (sys_obj);
ctrl_pair_creat ion_02 ccp2 = new ctrl_pair_creat ion_02 (sys_obj);
ctrl_pair_creat ion_03 ccp3 = new ctrl_pair_creat ion_03 (sys_obj);

ccp1.create_ctr l_pair_01 ();
ccp2.create_ctr l_pair_02 ();
ccp3.create_ctr l_pair_03 ();
}
/* - - - - - - - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - - - - - - - */
protected class base_create_ctr l_pair
{
protected TextBox UserTextBox0x;
protected Button button0x;
protected ControlCollecti on ph01_ctrl;
protected PlaceHolder base_Dyn_Ctrl_P laceholder;
protected Label Dyn_Lbl_msg01;

// constructor
protected base_create_ctr l_pair (sys_obj_class sys_obj)
{ ph01_ctrl = sys_obj.Get_pra m_ph01_ctrl;
base_Dyn_Ctrl_P laceholder = sys_obj.Get_Obj _Dyn_Ctrl_Place holder;
Dyn_Lbl_msg01 = sys_obj.Get_Obj _Dyn_Label01;
}

protected TextBox create_text_box _control (String text_box_id)
{ // Create UserTextBox TextBox control.
TextBox new_TextBox = new TextBox ();

// Configure the UserTextBox TextBox control.
new_TextBox.ID = text_box_id;

// Add UserTextBox TextBox control to the Controls collection
// of the Dyn_Control_Pla ceholder PlaceHolder control.
ph01_ctrl.Add (new_TextBox);

return new_TextBox;
}

/* --------------------------------------------------------- *
Example: The following example creates a Button,
sets its DialogResult property to DialogResult.OK ,
and adds it to a Form.
* --------------------------------------------------------- */
protected void InitializeMyBut ton (String Btn_ID, String Btn_text)
{ // Create and initialize a Button.
button0x = new Button();
button0x.ID = Btn_ID;
button0x.Text = Btn_text;

ph01_ctrl.Add ( new LiteralControl( "<br><br>") );
ph01_ctrl.Add (button0x);
}

protected void init_single_lin e_text_box (TextBox new_TextBox, int col_sz)
{ new_TextBox.Col umns = col_sz; }

protected void create_ctrl_pai r_0x
(String TB_ID, String DB_ID, String DB_txt)
{ // Create UserTextBox TextBox control.
UserTextBox0x = create_text_box _control (TB_ID);
InitializeMyBut ton(DB_ID, DB_txt);
}

/* -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- */
private String submit_click_st r01 = "The TextBox";

private String submit_click_st r02
= " control above is dynamically generated. <br> You entered: ";
public void Submit_Click (Object sender, EventArgs e)
{ // Retrieve the UserTextBox TextBox control from the
Dyn_Control_Pla ceholder
// PlaceHolder control.
TextBox TempTextBox = (TextBox)
base_Dyn_Ctrl_P laceholder.Find Control("UserTe xtBox1");

// Display the Text property.
Dyn_Lbl_msg01.T ext = submit_click_st r01 + '1' + submit_click_st r02 +
TempTextBox.Tex t;
}

public void Submit_Click2(O bject sender, EventArgs e)
{ TextBox TempTextBox = (TextBox)
base_Dyn_Ctrl_P laceholder.Find Control("UserTe xtBox2");
Dyn_Lbl_msg01.T ext = submit_click_st r01 + '2' + submit_click_st r02 +
TempTextBox.Tex t;
}

public void Submit_Click3(O bject sender, EventArgs e)
{ TextBox TempTextBox = (TextBox)
base_Dyn_Ctrl_P laceholder.Find Control("UserTe xtBox3");
Dyn_Lbl_msg01.T ext = submit_click_st r01 + '3' + submit_click_st r02 +
TempTextBox.Tex t;
}
/* -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- */

}
/* - - - - - - - - - - - - - - - - - - - - - - */

/* - - - - - - - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - - - - - - - */
protected class ctrl_pair_creat ion_01 : base_create_ctr l_pair
{
private sys_obj_class lcl_sys_obj;

public ctrl_pair_creat ion_01 (sys_obj_class sys_obj) : base (sys_obj)
{ lcl_sys_obj = sys_obj; }
//{ base_create_ctr l_pair (pram_ph01_ctrl ); }

/* . . . . . . . . . . . . . */
public void create_ctrl_pai r_01 ()
{ create_ctrl_pai r_0x
("UserTextBox1" , "DButton01" , "Submit 01");

button0x.Click += new EventHandler (Submit_Click);

if (!lcl_sys_obj.G et_this_page01. IsPostBack)
init_single_lin e_text_box (UserTextBox0x, 22);

ph01_ctrl.Add ( new LiteralControl( "<br><br>") );
}
/* . . . . . . . . . . . . . */
}
/* - - - - - - - - - - - - - - - - - - - - - - */
protected class ctrl_pair_creat ion_02 : base_create_ctr l_pair
{
private sys_obj_class lcl_sys_obj;

public ctrl_pair_creat ion_02 (sys_obj_class sys_obj) : base (sys_obj)
{ lcl_sys_obj = sys_obj; }
//{ base_create_ctr l_pair (pram_ph01_ctrl ); }

/* . . . . . . . . . . . . . */
public void create_ctrl_pai r_02 ()
{ // Create UserTextBox TextBox control.
create_ctrl_pai r_0x
("UserTextBox2" , "DButton02" , "Submit 02");

button0x.Click += new EventHandler (Submit_Click2) ;

if (!lcl_sys_obj.G et_this_page01. IsPostBack)
init_single_lin e_text_box (UserTextBox0x, 22);

ph01_ctrl.Add ( new LiteralControl( "<br><br>") );
}
/* . . . . . . . . . . . . . */
}
/* - - - - - - - - - - - - - - - - - - - - - - */
protected class ctrl_pair_creat ion_03 : base_create_ctr l_pair
{
private sys_obj_class lcl_sys_obj;

public ctrl_pair_creat ion_03 (sys_obj_class sys_obj) : base (sys_obj)
{ lcl_sys_obj = sys_obj; }
//{ base_create_ctr l_pair (pram_ph01_ctrl ); }

/* . . . . . . . . . . . . . */
public void create_ctrl_pai r_03 ()
{ // Create UserTextBox TextBox control.
create_ctrl_pai r_0x
("UserTextBox3" , "DButton03" , "Submit 03");

button0x.Click += new EventHandler (Submit_Click3) ;

if (!lcl_sys_obj.G et_this_page01. IsPostBack)
init_single_lin e_text_box (UserTextBox0x, 22);

ph01_ctrl.Add ( new LiteralControl( "<br><br>") );
}
/* . . . . . . . . . . . . . */
}
/* - - - - - - - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - - - - - - - */

</script>
</head>

<body>

<form runat="server">

<h3> TextBox Constructor Example </h3>

Enter some text and click the Submit button. <br><br>

<asp:PlaceHolde r ID="Dyn_Control _Placeholder" runat="server"/>

<asp:Label ID="Message01" runat="server"/>

</form>

</body>
</html>

/-\_/-\_/-\_/-\_/-\_/-\_/-\_/-\_/-\_/-\_/-\_/-\_/-\_/-\_/-\_/-\_/-\
\_/-\_/-\_/-\_/-\_/-\_/-\_/-\_/-\_/-\_/-\_/-\_/-\_/-\_/-\_/-\_/-\-/

As you can see, I’ve gathered up all of the needed objects,
and encapsulated them in a sys_obj (public class sys_obj_class)
- and now it’s just a matter of passing that object around
to the control-construction classes. If I want to construct
any controls for any additional placeholder/label pairs,
all I have to do is to pass the ID’s for each respective
pair to the FindControl functions (to get the associated objects),
then construct a corresponding sys_obj for that pair:
- - - - - - - - - - - - - - -
plc_hldr = (PlaceHolder) FindControl ("Dyn_Control_P laceholder02");
lbl_msg01 = (Label) FindControl ("Message02" );
sys_obj_class sys_obj02 = new sys_obj_class (plc_hldr, lbl_msg01);
- - - - - - - - - - - - - - -
- - - - - - - - - - - - - - -

... and place the necessary tags in the HTML section of course.
The next step is to create and manage viewstate for each respective
dynamic web control. By doing that, I can make random insertions
(“addat”) and deletions to the hierarchy without messing up
the viewstate for the page as a whole. I was looking through some
of the docs for that, but I’m not sure if I have a good understanding
of what I was reading as of yet. I’m thinking that my C# books will
give me a better idea.

... and then there’ll be input validation to attach to this mess.
Thanks a lot Wessel - you're wonderful.
- wASP
Nov 17 '05 #7

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

Similar topics

4
1715
by: Raymond Arthur St. Marie II of III | last post by:
very Very VERY dumb ? about the new Set( ) 's Please be kind and read this like you know I've been up 33-34 hours reading PEP's but... Doc\ref 2.6 Delimiters show's three unused characters "@ $ ?". @ sort of looks like and sort of sounds like a set an $ well sort of obvious. I can imagine that the $ would be confused for money and @ is ugly.
4
4025
by: blu4899 | last post by:
Hi, The Xerces XML parser is reading external DTD references in DOCTYPEs by default, but is not doing anything with them because validation is turned off by default. This is documented in http://xml.apache.org/xerces2-j/features.html#nonvalidating.load-external-dtd This setting causes many XML instances with broken DTD references in the DOCTYPE to fail and adds some performance overhead. Is there anything good that comes from this...
6
2492
by: Stephen Cook | last post by:
Having worked through the problems around enabling the document function using an XmlUrlResolver I started work on building a useful class to hide the intricacies. Trying to generalise the process I've hit a snag. How do I resolve multiple external references? The transform method on a stylesheet only takes one resolver, not an array Stephen
1
2000
by: S. van Beek | last post by:
Dear reader, In case an application is ussing an external model library you have to address this external model library in your application. This addressing takes place in a module of the application by opening of a module and activates and than brows to the location of the external library.
3
3828
by: S. van Beek | last post by:
Dear reader, In the module window you can make a link to an external library within the reference form. The reference form can be activated with Tools/References... In the menu bar.
5
3650
by: snicks | last post by:
I'm trying to exec a program external to my ASP.NET app using the following code. The external app is a VB.NET application. Dim sPPTOut As String sPPTOut = MDEPDirStr + sID + ".ppt" Dim p As New System.Diagnostics.Process 'p.Start(MDEPDirStr & "macrun.exe", sPPTOut) p.Start("C:\WINDOWS\SYSTEM32\CALC.EXE") 'p.Start("C:\WINDOWS\SYSTEM32\macrun.exe", sPPTOut)
10
2268
by: sp | last post by:
I create an xml file in a text editor: <?xml version="1.0" encoding="utf-8"?> <elts> <elt id="1" class="c1">content1</elt> <elt id="2" class="c1">content2</elt> </elts> Then I load the file via xmlHttpRequest into xmlData variable. Why does xmlData.getElementById('1') return null and xmlData.firstChild.childNodes.className returns null also?
0
2708
by: Ryan Gaffuri | last post by:
hlink72@hotmail.com (Eric) wrote in message news:<ab8d8b14.0308220550.54fb5f22@posting.google.com>... LNK1120 is a standard C++ error. you using Visual C++? Means your references a class that doesnt exist or something similiar to that. explanation on microsoft.com its not an oracle specific problem.
4
3255
by: =?Utf-8?B?U0g=?= | last post by:
There seems to be an issue with .NET 3.5/Visual Studio 2008 (Team System). After convincing my company to create our latest project in .NET 3.5, this is kind of reflecting bad on me. Problem: Solution will NOT compile. Error is simply: "External component has thrown an exception". NO other details.
0
9703
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10317
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10295
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9125
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6844
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5501
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3799
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2972
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.