473,503 Members | 13,285 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_ctrl_pair
{
public ccp_01 (ControlCollection pram_ph01_ctrl)
: base (pram_ph01_ctrl) {}
//{ base_create_ctrl_pair (pram_ph01_ctrl); }

public void create_ctrl_pair_01 ()
{ create_ctrl_pair_0x
("UserTextBox1", "DButton01", "Submit 01");

button0x.Click += new EventHandler (Submit_Click);

if (!Page.IsPostBack)
init_single_line_text_box (UserTextBox0x, 22);

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

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

/* -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- */
public void Submit_Click(Object sender, EventArgs e)
{ // Retrieve the UserTextBox TextBox control from the TextBoxControlPlaceHolder
// PlaceHolder control.

TextBox TempTextBox
= (TextBox)TextBoxControlPlaceHolder.FindControl("Us erTextBox1");

// Display the Text property.
Message.Text
= submit_click_str01 + '1' + submit_click_str02 + TempTextBox.Text;
}
. . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . .

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

C:\WINNT\system32> "c:\winnt\microsoft.net\framework\v1.1.4322\csc.ex e"
/t:library /utf8output
/R:"c:\winnt\assembly\gac\system.enterpriseservices \1.0.5000.0__b03f5f7f11d50a3a
\system.enterpriseservices.dll"
/R:"c:\winnt\assembly\gac\system.data\1.0.5000.0__b 77a5c561934e089\system.data.dll"

/R:"c:\winnt\assembly\gac\system.drawing\1.0.5000.0 __b03f5f7f11d50a3a\system.drawing.dll"

/R:"c:\winnt\assembly\gac\system.web.mobile\1.0.500 0.0__b03f5f7f11d50a3a\system.web.mobile.dll"
/R:"c:\winnt\assembly\gac\system.xml\1.0.5000.0__b7 7a5c561934e089\system.xml.dll"

/R:"c:\winnt\assembly\gac\system.web.services\1.0.5 000.0__b03f5f7f11d50a3a\system.web.services.dll"
/R:"c:\winnt\assembly\gac\system\1.0.5000.0__b77a5c 561934e089\system.dll"
/R:"c:\winnt\assembly\gac\system.web\1.0.5000.0__b0 3f5f7f11d50a3a\system.web.dll"
/R:"c:\winnt\microsoft.net\framework\v1.1.4322\msco rlib.dll"
/out:"C:\WINNT\Microsoft.NET\Framework\v1.1.4322\Te mporary ASP.NET Files

\webfolder01\08460e05\9c82db3e\rdoqxnq-.dll"
/debug- /optimize+ /warnaserror
/w:1 "C:\WINNT\Microsoft.NET\Framework\v1.1.4322\Tempor ary ASP.NET Files

\webfolder01\08460e05\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\ViewState02.aspx(123,50): error CS0038:
Cannot access a nonstatic member of outer type 'ASP.ViewState02_aspx'
via nested type 'ASP.ViewState02_aspx.ccp_01'

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

[if (!Page.IsPostBack)]

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

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 2478
> I'm having a problem with referencing methods/functions external
to a class member function.

It looks like you're calling System.Web.Ui.Page 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.the.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.Page 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_str01 = "The TextBox";

String submit_click_str02
= " control above is dynamically generated. <br> You entered: ";
/* -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- */
public void Submit_Click(Object sender, EventArgs e)
{ TextBox TempTextBox =
(TextBox)TextBoxControlPlaceHolder.FindControl("Us erTextBox1");
Message.Text = submit_click_str01 + '1' + submit_click_str02 +
TempTextBox.Text;
}

protected void Submit_Click2(Object sender, EventArgs e)
{ TextBox TempTextBox =
(TextBox)TextBoxControlPlaceHolder.FindControl("Us erTextBox2");
Message.Text = submit_click_str01 + '2' + submit_click_str02 +
TempTextBox.Text;
}

protected void Submit_Click3(Object sender, EventArgs e)
{ TextBox TempTextBox =
(TextBox)TextBoxControlPlaceHolder.FindControl("Us erTextBox3");
Message.Text = submit_click_str01 + '3' + submit_click_str02 +
TempTextBox.Text;
}
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
protected void Page_Load(Object sender, EventArgs e)
{
ControlCollection pram_ph01_ctrl = TextBoxControlPlaceHolder.Controls;

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_ctrl_pair_01 ();
ccp2.create_ctrl_pair_02 ();
ccp3.create_ctrl_pair_03 ();
}
/* - - - - - - - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - - - - - - - */
public class base_create_ctrl_pair
{
protected TextBox UserTextBox0x;
protected Button button0x;
protected ControlCollection ph01_ctrl;

// constructor
protected base_create_ctrl_pair (ControlCollection 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 TextBoxControlPlaceHolder PlaceHolder control.
ph01_ctrl.Add (new_TextBox);

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

/* --------------------------------------------------------- */
/* --------------------------------------------------------- */
protected void InitializeMyButton (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_line_text_box (TextBox new_TextBox, int col_sz)
{ new_TextBox.Columns = col_sz; }

protected void create_ctrl_pair_0x
(String TB_ID, String DB_ID, String DB_txt)
{ // Create UserTextBox TextBox control.
UserTextBox0x = create_text_box_control (TB_ID);
InitializeMyButton (DB_ID, DB_txt);
}
} /* END: public class base_create_ctrl_pair */
/* - - - - - - - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - - - - - - - */

/* - - - - - - - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - - - - - - - */
public class ccp_01 : base_create_ctrl_pair
{
// constructor
public ccp_01 (ControlCollection pram_ph01_ctrl)
: base (pram_ph01_ctrl) {}

public void create_ctrl_pair_01 ()
{ create_ctrl_pair_0x
("UserTextBox1", "DButton01", "Submit 01");

button0x.Click += new EventHandler (Submit_Click);

if (!Page.IsPostBack)
init_single_line_text_box (UserTextBox0x, 22);

ph01_ctrl.Add ( new LiteralControl("<br><br>") );
}
}
/* - - - - - - - - - - - - - - - - - - - - - - */
public class ccp_02 : base_create_ctrl_pair
{
public ccp_02 (ControlCollection pram_ph01_ctrl)
: base (pram_ph01_ctrl) {}

public void create_ctrl_pair_02 ()
{ // Create UserTextBox TextBox control.
create_ctrl_pair_0x
("UserTextBox2", "DButton02", "Submit 02");

button0x.Click += new EventHandler (Submit_Click2);

if (!Page.IsPostBack)
init_single_line_text_box (UserTextBox0x, 22);

ph01_ctrl.Add ( new LiteralControl("<br><br>") );
}
}
/* - - - - - - - - - - - - - - - - - - - - - - */
public class ccp_03 : base_create_ctrl_pair
{
public ccp_03 (ControlCollection pram_ph01_ctrl)
: base (pram_ph01_ctrl) {}

public void create_ctrl_pair_03 ()
{ // Create UserTextBox TextBox control.
create_ctrl_pair_0x
("UserTextBox3", "DButton03", "Submit 03");

button0x.Click += new EventHandler (Submit_Click3);

if (!Page.IsPostBack)
init_single_line_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:PlaceHolder ID="TextBoxControlPlaceHolder" 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\Clean\ViewState02.aspx(109,52): error CS0038:
Cannot access a nonstatic member of outer type 'ASP.ViewState02_aspx'
via nested type 'ASP.ViewState02_aspx.ccp_01'

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

I:\Virtual Webfolders\Clean\ViewState02.aspx(128,50): error CS0038:
Cannot access a nonstatic member of outer type 'ASP.ViewState02_aspx'
via nested type 'ASP.ViewState02_aspx.ccp_02'

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

I:\Virtual Webfolders\Clean\ViewState02.aspx(147,50): error CS0038:
Cannot access a nonstatic member of outer type 'ASP.ViewState02_aspx'
via nested type 'ASP.ViewState02_aspx.ccp_03'

I:\Virtual Webfolders\Clean\ViewState02.aspx(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.Method();
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_str01 = "The TextBox";

String submit_click_str02
= " control above is dynamically generated. <br> You entered: ";
/*
-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- */
public void Submit_Click(Object sender, EventArgs e)
{ TextBox TempTextBox =
(TextBox)TextBoxControlPlaceHolder.FindControl("Us erTextBox1");
Message.Text = submit_click_str01 + '1' + submit_click_str02 +
TempTextBox.Text;
}

protected void Submit_Click2(Object sender, EventArgs e)
{ TextBox TempTextBox =
(TextBox)TextBoxControlPlaceHolder.FindControl("Us erTextBox2");
Message.Text = submit_click_str01 + '2' + submit_click_str02 +
TempTextBox.Text;
}

protected void Submit_Click3(Object sender, EventArgs e)
{ TextBox TempTextBox =
(TextBox)TextBoxControlPlaceHolder.FindControl("Us erTextBox3");
Message.Text = submit_click_str01 + '3' + submit_click_str02 +
TempTextBox.Text;
}
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
protected void Page_Load(Object sender, EventArgs e)
{
ControlCollection pram_ph01_ctrl =
TextBoxControlPlaceHolder.Controls;

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_ctrl_pair_01(new EventHandler(Submit_Click),
this.IsPostBack);
ccp2.create_ctrl_pair_02(new EventHandler(Submit_Click2),
this.IsPostBack);
ccp3.create_ctrl_pair_03(new EventHandler(Submit_Click3),
this.IsPostBack);
}
/* - - - - - - - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - - - - - - - */
public class base_create_ctrl_pair
{
protected TextBox UserTextBox0x;
protected Button button0x;
protected ControlCollection ph01_ctrl;

// constructor
protected base_create_ctrl_pair (ControlCollection
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 TextBoxControlPlaceHolder PlaceHolder control.
ph01_ctrl.Add (new_TextBox);

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

/* --------------------------------------------------------- */
/* --------------------------------------------------------- */
protected void InitializeMyButton (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_line_text_box (TextBox new_TextBox,
int col_sz)
{ new_TextBox.Columns = col_sz; }

protected void create_ctrl_pair_0x
(String TB_ID, String DB_ID, String DB_txt)
{ // Create UserTextBox TextBox control.
UserTextBox0x = create_text_box_control (TB_ID);
InitializeMyButton (DB_ID, DB_txt);
}
} /* END: public class base_create_ctrl_pair */
/* - - - - - - - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - - - - - - - */

/* - - - - - - - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - - - - - - - */
public class ccp_01 : base_create_ctrl_pair
{
// constructor
public ccp_01 (ControlCollection pram_ph01_ctrl )
: base (pram_ph01_ctrl) {}

public void create_ctrl_pair_01 ( EventHandler oEventHandler,
bool bIsPostback )
{ create_ctrl_pair_0x
("UserTextBox1", "DButton01", "Submit 01");

button0x.Click += oEventHandler;

if (!bIsPostback)
init_single_line_text_box (UserTextBox0x, 22);

ph01_ctrl.Add ( new LiteralControl("<br><br>") );
}
}
/* - - - - - - - - - - - - - - - - - - - - - - */
public class ccp_02 : base_create_ctrl_pair
{
public ccp_02 (ControlCollection pram_ph01_ctrl)
: base (pram_ph01_ctrl) {}

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

button0x.Click += oEventHandler;

if (!bIsPostBack)
init_single_line_text_box (UserTextBox0x, 22);

ph01_ctrl.Add ( new LiteralControl("<br><br>") );
}
}
/* - - - - - - - - - - - - - - - - - - - - - - */
public class ccp_03 : base_create_ctrl_pair
{
public ccp_03 (ControlCollection pram_ph01_ctrl)
: base (pram_ph01_ctrl) {}

public void create_ctrl_pair_03(EventHandler oEventHandler, bool
bIsPostBack)
{ // Create UserTextBox TextBox control.
create_ctrl_pair_0x
("UserTextBox3", "DButton03", "Submit 03");

button0x.Click += oEventHandler;

if (!bIsPostBack)
init_single_line_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:PlaceHolder ID="TextBoxControlPlaceHolder" 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.the.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.Method();
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_ctrl 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.Page ThePage = ...;
ThePage.IsPostback()

Greetings,
Wessel
Nov 17 '05 #6
On Wed, 27 Jul 2005 09:24:48 +0200, "Wessel Troost" <no*****@like.the.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.Page ThePage = ...;
ThePage.IsPostback()


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 ControlCollection pram_ph01_ctrl;
public ControlCollection Get_pram_ph01_ctrl
{ get { return pram_ph01_ctrl; } }

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

private PlaceHolder Obj_Dyn_Ctrl_Placeholder;
public PlaceHolder Get_Obj_Dyn_Ctrl_Placeholder
{ get { return Obj_Dyn_Ctrl_Placeholder; } }

private Label Obj_Dyn_Label01;
public Label Get_Obj_Dyn_Label01
{ get { return Obj_Dyn_Label01; } }
public sys_obj_class
(PlaceHolder Dyn_Ctrl_Placeholder, Label Dyn_Label)
{ pram_ph01_ctrl = Dyn_Ctrl_Placeholder.Controls;
this_page01 = Dyn_Ctrl_Placeholder.Page;
Obj_Dyn_Ctrl_Placeholder = Dyn_Ctrl_Placeholder;
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_Placeholder");
Label lbl_msg01 = (Label) FindControl ("Message01");
sys_obj_class sys_obj = new sys_obj_class (plc_hldr, lbl_msg01);

ctrl_pair_creation_01 ccp1 = new ctrl_pair_creation_01 (sys_obj);
ctrl_pair_creation_02 ccp2 = new ctrl_pair_creation_02 (sys_obj);
ctrl_pair_creation_03 ccp3 = new ctrl_pair_creation_03 (sys_obj);

ccp1.create_ctrl_pair_01 ();
ccp2.create_ctrl_pair_02 ();
ccp3.create_ctrl_pair_03 ();
}
/* - - - - - - - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - - - - - - - */
protected class base_create_ctrl_pair
{
protected TextBox UserTextBox0x;
protected Button button0x;
protected ControlCollection ph01_ctrl;
protected PlaceHolder base_Dyn_Ctrl_Placeholder;
protected Label Dyn_Lbl_msg01;

// constructor
protected base_create_ctrl_pair (sys_obj_class sys_obj)
{ ph01_ctrl = sys_obj.Get_pram_ph01_ctrl;
base_Dyn_Ctrl_Placeholder = sys_obj.Get_Obj_Dyn_Ctrl_Placeholder;
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_Placeholder 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 InitializeMyButton (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_line_text_box (TextBox new_TextBox, int col_sz)
{ new_TextBox.Columns = col_sz; }

protected void create_ctrl_pair_0x
(String TB_ID, String DB_ID, String DB_txt)
{ // Create UserTextBox TextBox control.
UserTextBox0x = create_text_box_control (TB_ID);
InitializeMyButton(DB_ID, DB_txt);
}

/* -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- */
private String submit_click_str01 = "The TextBox";

private String submit_click_str02
= " 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_Placeholder
// PlaceHolder control.
TextBox TempTextBox = (TextBox)
base_Dyn_Ctrl_Placeholder.FindControl("UserTextBox 1");

// Display the Text property.
Dyn_Lbl_msg01.Text = submit_click_str01 + '1' + submit_click_str02 +
TempTextBox.Text;
}

public void Submit_Click2(Object sender, EventArgs e)
{ TextBox TempTextBox = (TextBox)
base_Dyn_Ctrl_Placeholder.FindControl("UserTextBox 2");
Dyn_Lbl_msg01.Text = submit_click_str01 + '2' + submit_click_str02 +
TempTextBox.Text;
}

public void Submit_Click3(Object sender, EventArgs e)
{ TextBox TempTextBox = (TextBox)
base_Dyn_Ctrl_Placeholder.FindControl("UserTextBox 3");
Dyn_Lbl_msg01.Text = submit_click_str01 + '3' + submit_click_str02 +
TempTextBox.Text;
}
/* -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- */

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

/* - - - - - - - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - - - - - - - */
protected class ctrl_pair_creation_01 : base_create_ctrl_pair
{
private sys_obj_class lcl_sys_obj;

public ctrl_pair_creation_01 (sys_obj_class sys_obj) : base (sys_obj)
{ lcl_sys_obj = sys_obj; }
//{ base_create_ctrl_pair (pram_ph01_ctrl); }

/* . . . . . . . . . . . . . */
public void create_ctrl_pair_01 ()
{ create_ctrl_pair_0x
("UserTextBox1", "DButton01", "Submit 01");

button0x.Click += new EventHandler (Submit_Click);

if (!lcl_sys_obj.Get_this_page01.IsPostBack)
init_single_line_text_box (UserTextBox0x, 22);

ph01_ctrl.Add ( new LiteralControl("<br><br>") );
}
/* . . . . . . . . . . . . . */
}
/* - - - - - - - - - - - - - - - - - - - - - - */
protected class ctrl_pair_creation_02 : base_create_ctrl_pair
{
private sys_obj_class lcl_sys_obj;

public ctrl_pair_creation_02 (sys_obj_class sys_obj) : base (sys_obj)
{ lcl_sys_obj = sys_obj; }
//{ base_create_ctrl_pair (pram_ph01_ctrl); }

/* . . . . . . . . . . . . . */
public void create_ctrl_pair_02 ()
{ // Create UserTextBox TextBox control.
create_ctrl_pair_0x
("UserTextBox2", "DButton02", "Submit 02");

button0x.Click += new EventHandler (Submit_Click2);

if (!lcl_sys_obj.Get_this_page01.IsPostBack)
init_single_line_text_box (UserTextBox0x, 22);

ph01_ctrl.Add ( new LiteralControl("<br><br>") );
}
/* . . . . . . . . . . . . . */
}
/* - - - - - - - - - - - - - - - - - - - - - - */
protected class ctrl_pair_creation_03 : base_create_ctrl_pair
{
private sys_obj_class lcl_sys_obj;

public ctrl_pair_creation_03 (sys_obj_class sys_obj) : base (sys_obj)
{ lcl_sys_obj = sys_obj; }
//{ base_create_ctrl_pair (pram_ph01_ctrl); }

/* . . . . . . . . . . . . . */
public void create_ctrl_pair_03 ()
{ // Create UserTextBox TextBox control.
create_ctrl_pair_0x
("UserTextBox3", "DButton03", "Submit 03");

button0x.Click += new EventHandler (Submit_Click3);

if (!lcl_sys_obj.Get_this_page01.IsPostBack)
init_single_line_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:PlaceHolder 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_Placeholder02");
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
1690
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 "@...
4
4008
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...
6
2467
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...
1
1987
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...
3
3804
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
3612
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...
10
2226
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...
0
2694
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...
4
3230
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:...
0
7212
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
7364
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...
1
7017
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...
0
5604
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,...
0
4696
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...
0
3186
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...
0
3174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
751
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
405
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...

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.