Showing posts with label slightly. Show all posts
Showing posts with label slightly. Show all posts

Saturday, March 24, 2012

passing variables

Hi,

I have this (thanks Clint) which I have modified slightly from Clints code.

using System;

namespace NewsGroupHelpASPNET
{
/// <summary>
/// Summary description for MyPage.
/// </summary>
public class PageClass
{
private Table tables;
private StringBuilder sb = null;

public PageClass()
{
}

public void WriteText(string textToWrite)
{
sb.Append(textToWrite)
}

public Table Tables
{
get { return this.tables; }
set { this.tables = value; }
}
}
public class Table
{
private Row[] rows;
public Table()
{

}
public Row[] Rows
{
get { return this.rows; }
set { this.rows = value; }
}
public Add(int Rows, int Cols)
{
}
public Close()
{
}
}
public class Row
{
private Cell[] cells;
public Row()
{

}
public Cell[] Cells
{
get { return this.cells; }
set { this.cells = value; }
}
}
public class Cell
{
private string cellText;
public Cell()
{

}
public string Text
{
get { return this.cellText; }
set { this.cellText = value; }
}
}
}

When I do table.Add(2, 2), I need to add some text into the StringBuilder sb
which is in the top level class PageClass. I will also need to do this
within the Row and Cell as well as Text.

On top of this, the 2, 2 in the Add, I will need to store somewhere so that
Row and Cell can access them.

Thanks for any help you can offer.

Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises availableAnybody?

Best regards,
Dave Colliver.
http://www.CoventryFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available

"David" <david.colliver.NEWS@.revilloc.REMOVETHIS.com> wrote in message
news:uKRCNuTkFHA.2444@.tk2msftngp13.phx.gbl...
> Hi,
> I have this (thanks Clint) which I have modified slightly from Clints
> code.
> using System;
> namespace NewsGroupHelpASPNET
> {
> /// <summary>
> /// Summary description for MyPage.
> /// </summary>
> public class PageClass
> {
> private Table tables;
> private StringBuilder sb = null;
> public PageClass()
> {
> }
> public void WriteText(string textToWrite)
> {
> sb.Append(textToWrite)
> }
> public Table Tables
> {
> get { return this.tables; }
> set { this.tables = value; }
> }
> }
> public class Table
> {
> private Row[] rows;
> public Table()
> {
> }
> public Row[] Rows
> {
> get { return this.rows; }
> set { this.rows = value; }
> }
> public Add(int Rows, int Cols)
> {
> }
> public Close()
> {
> }
> }
> public class Row
> {
> private Cell[] cells;
> public Row()
> {
> }
> public Cell[] Cells
> {
> get { return this.cells; }
> set { this.cells = value; }
> }
> }
> public class Cell
> {
> private string cellText;
> public Cell()
> {
> }
> public string Text
> {
> get { return this.cellText; }
> set { this.cellText = value; }
> }
> }
> }
>
> When I do table.Add(2, 2), I need to add some text into the StringBuilder
> sb which is in the top level class PageClass. I will also need to do this
> within the Row and Cell as well as Text.
> On top of this, the 2, 2 in the Add, I will need to store somewhere so
> that Row and Cell can access them.
> Thanks for any help you can offer.
> Best regards,
> Dave Colliver.
> http://www.AshfieldFOCUS.com
> ~~
> http://www.FOCUSPortals.com - Local franchises available
Anybody?

Best regards,
Dave Colliver.
http://www.CoventryFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available

"David" <david.colliver.NEWS@.revilloc.REMOVETHIS.com> wrote in message
news:uKRCNuTkFHA.2444@.tk2msftngp13.phx.gbl...
> Hi,
> I have this (thanks Clint) which I have modified slightly from Clints
> code.
> using System;
> namespace NewsGroupHelpASPNET
> {
> /// <summary>
> /// Summary description for MyPage.
> /// </summary>
> public class PageClass
> {
> private Table tables;
> private StringBuilder sb = null;
> public PageClass()
> {
> }
> public void WriteText(string textToWrite)
> {
> sb.Append(textToWrite)
> }
> public Table Tables
> {
> get { return this.tables; }
> set { this.tables = value; }
> }
> }
> public class Table
> {
> private Row[] rows;
> public Table()
> {
> }
> public Row[] Rows
> {
> get { return this.rows; }
> set { this.rows = value; }
> }
> public Add(int Rows, int Cols)
> {
> }
> public Close()
> {
> }
> }
> public class Row
> {
> private Cell[] cells;
> public Row()
> {
> }
> public Cell[] Cells
> {
> get { return this.cells; }
> set { this.cells = value; }
> }
> }
> public class Cell
> {
> private string cellText;
> public Cell()
> {
> }
> public string Text
> {
> get { return this.cellText; }
> set { this.cellText = value; }
> }
> }
> }
>
> When I do table.Add(2, 2), I need to add some text into the StringBuilder
> sb which is in the top level class PageClass. I will also need to do this
> within the Row and Cell as well as Text.
> On top of this, the 2, 2 in the Add, I will need to store somewhere so
> that Row and Cell can access them.
> Thanks for any help you can offer.
> Best regards,
> Dave Colliver.
> http://www.AshfieldFOCUS.com
> ~~
> http://www.FOCUSPortals.com - Local franchises available

passing variables

Hi,
I have this (thanks Clint) which I have modified slightly from Clints code.
using System;
namespace NewsGroupHelpASPNET
{
/// <summary>
/// Summary description for MyPage.
/// </summary>
public class PageClass
{
private Table tables;
private StringBuilder sb = null;
public PageClass()
{
}
public void WriteText(string textToWrite)
{
sb.Append(textToWrite)
}
public Table Tables
{
get { return this.tables; }
set { this.tables = value; }
}
}
public class Table
{
private Row[] rows;
public Table()
{
}
public Row[] Rows
{
get { return this.rows; }
set { this.rows = value; }
}
public Add(int Rows, int Cols)
{
}
public Close()
{
}
}
public class Row
{
private Cell[] cells;
public Row()
{
}
public Cell[] Cells
{
get { return this.cells; }
set { this.cells = value; }
}
}
public class Cell
{
private string cellText;
public Cell()
{
}
public string Text
{
get { return this.cellText; }
set { this.cellText = value; }
}
}
}
When I do table.Add(2, 2), I need to add some text into the StringBuilder sb
which is in the top level class PageClass. I will also need to do this
within the Row and Cell as well as Text.
On top of this, the 2, 2 in the Add, I will need to store somewhere so that
Row and Cell can access them.
Thanks for any help you can offer.
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises availableAnybody?
Best regards,
Dave Colliver.
http://www.CoventryFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
"David" <david.colliver.NEWS@.revilloc.REMOVETHIS.com> wrote in message
news:uKRCNuTkFHA.2444@.tk2msftngp13.phx.gbl...
> Hi,
> I have this (thanks Clint) which I have modified slightly from Clints
> code.
> using System;
> namespace NewsGroupHelpASPNET
> {
> /// <summary>
> /// Summary description for MyPage.
> /// </summary>
> public class PageClass
> {
> private Table tables;
> private StringBuilder sb = null;
> public PageClass()
> {
> }
> public void WriteText(string textToWrite)
> {
> sb.Append(textToWrite)
> }
> public Table Tables
> {
> get { return this.tables; }
> set { this.tables = value; }
> }
> }
> public class Table
> {
> private Row[] rows;
> public Table()
> {
> }
> public Row[] Rows
> {
> get { return this.rows; }
> set { this.rows = value; }
> }
> public Add(int Rows, int Cols)
> {
> }
> public Close()
> {
> }
> }
> public class Row
> {
> private Cell[] cells;
> public Row()
> {
> }
> public Cell[] Cells
> {
> get { return this.cells; }
> set { this.cells = value; }
> }
> }
> public class Cell
> {
> private string cellText;
> public Cell()
> {
> }
> public string Text
> {
> get { return this.cellText; }
> set { this.cellText = value; }
> }
> }
> }
>
> When I do table.Add(2, 2), I need to add some text into the StringBuilder
> sb which is in the top level class PageClass. I will also need to do this
> within the Row and Cell as well as Text.
> On top of this, the 2, 2 in the Add, I will need to store somewhere so
> that Row and Cell can access them.
> Thanks for any help you can offer.
> Best regards,
> Dave Colliver.
> http://www.AshfieldFOCUS.com
> ~~
> http://www.FOCUSPortals.com - Local franchises available
>

Wednesday, March 21, 2012

passing variables to a user control

Hi
I'm new to C#, moving from ASP, and slightly so bear with me!
Basically I've got 4 pages, each of which runs the same user control (some
header information). I want to be able to change the data in the user contro
l
based on the page (everything else would be duplicated, hence the user
control).
Anyway, i thought the easiest way would be to use a variable set in the
Page_load event of the calling page. So I've got a variable defined in my
page class as..
public int pageID = 1;
However, when I try to access that from the user control, it says the
variable is not defined in the namespace. What am i missing!?!
Alternatively, I could use a URL object to get the page were on directly in
the usercontrol, but I couldnt find a URL method/property to give me just th
e
file name.
Hope all that makes sense!
Cheers
DanYou should try to put a public property on your user control. In your html
code set your property.
<uc1:UserControl id="MyControl" runat="server"
MyPublicProp="1"></uc1:UserControl>
If you want to do this from code, first, you should declare your user
control in your page because visual studion didn't do this by default.
it should look like this
protected MyPath.To.Control.ControlName MyControl;
after this you can acces your control properties normally..
MyControl.MyPublicProp ="1";
Cheers
"Dan Nash" wrote:

> Hi
> I'm new to C#, moving from ASP, and slightly so bear with me!
> Basically I've got 4 pages, each of which runs the same user control (some
> header information). I want to be able to change the data in the user cont
rol
> based on the page (everything else would be duplicated, hence the user
> control).
> Anyway, i thought the easiest way would be to use a variable set in the
> Page_load event of the calling page. So I've got a variable defined in my
> page class as..
> public int pageID = 1;
> However, when I try to access that from the user control, it says the
> variable is not defined in the namespace. What am i missing!?!
> Alternatively, I could use a URL object to get the page were on directly i
n
> the usercontrol, but I couldnt find a URL method/property to give me just
the
> file name.
> Hope all that makes sense!
> Cheers
>
> Dan
>
Hi,
Create an interface. eg:
public interface ICommonPage
{
int PageID{get;}
}
then implement it in the classes that contain the usercontrol in question
like this:
public class page1 : System.Web.UI.Page, ICommonPage
{
//Hardcode the value in a field:
int _PageID = 1; // or 2 in page2, 3 in page3, etc.
// The actual implementation:
public ICommonPage.PageID
{
get{return _PageID;}
}
// the rest of the class as it is...
}
And finally in the usercontrol cast the Page property to the interface and
get the value:
int PageID = ((ICommonPage)Page).PageID;
// work with PageID...
Hope this helps
Martin
"Dan Nash" <dan@.musoswire.co.uk> wrote in message
news:1D302C45-765A-46AE-AB82-631BB104CB6A@.microsoft.com...
> Hi
> I'm new to C#, moving from ASP, and slightly so bear with me!
> Basically I've got 4 pages, each of which runs the same user control (some
> header information). I want to be able to change the data in the user
control
> based on the page (everything else would be duplicated, hence the user
> control).
> Anyway, i thought the easiest way would be to use a variable set in the
> Page_load event of the calling page. So I've got a variable defined in my
> page class as..
> public int pageID = 1;
> However, when I try to access that from the user control, it says the
> variable is not defined in the namespace. What am i missing!?!
> Alternatively, I could use a URL object to get the page were on directly
in
> the usercontrol, but I couldnt find a URL method/property to give me just
the
> file name.
> Hope all that makes sense!
> Cheers
>
> Dan
>
Thanks guys!
Psychos post solved it, I guess you would say, the easy way! However,
Martin's solution looks interesting.. might try that one when I know a bit
more about C# (only got it Friday!).
Would there be any advantage with ICommonPage over the second method that
Psycho suggested?
Cheers guys
Dan
"Dan Nash" wrote:

> Hi
> I'm new to C#, moving from ASP, and slightly so bear with me!
> Basically I've got 4 pages, each of which runs the same user control (some
> header information). I want to be able to change the data in the user cont
rol
> based on the page (everything else would be duplicated, hence the user
> control).
> Anyway, i thought the easiest way would be to use a variable set in the
> Page_load event of the calling page. So I've got a variable defined in my
> page class as..
> public int pageID = 1;
> However, when I try to access that from the user control, it says the
> variable is not defined in the namespace. What am i missing!?!
> Alternatively, I could use a URL object to get the page were on directly i
n
> the usercontrol, but I couldnt find a URL method/property to give me just
the
> file name.
> Hope all that makes sense!
> Cheers
>
> Dan
>

passing variables to a user control

Hi

I'm new to C#, moving from ASP, and slightly confused so bear with me!

Basically I've got 4 pages, each of which runs the same user control (some
header information). I want to be able to change the data in the user control
based on the page (everything else would be duplicated, hence the user
control).

Anyway, i thought the easiest way would be to use a variable set in the
Page_load event of the calling page. So I've got a variable defined in my
page class as..

public int pageID = 1;

However, when I try to access that from the user control, it says the
variable is not defined in the namespace. What am i missing!?!

Alternatively, I could use a URL object to get the page were on directly in
the usercontrol, but I couldnt find a URL method/property to give me just the
file name.

Hope all that makes sense!

Cheers

DanYou should try to put a public property on your user control. In your html
code set your property.

<uc1:UserControl id="MyControl" runat="server"
MyPublicProp="1"></uc1:UserControl
If you want to do this from code, first, you should declare your user
control in your page because visual studion didn't do this by default.

it should look like this
protected MyPath.To.Control.ControlName MyControl;
after this you can acces your control properties normally..

MyControl.MyPublicProp ="1";

Cheers
"Dan Nash" wrote:

> Hi
> I'm new to C#, moving from ASP, and slightly confused so bear with me!
> Basically I've got 4 pages, each of which runs the same user control (some
> header information). I want to be able to change the data in the user control
> based on the page (everything else would be duplicated, hence the user
> control).
> Anyway, i thought the easiest way would be to use a variable set in the
> Page_load event of the calling page. So I've got a variable defined in my
> page class as..
> public int pageID = 1;
> However, when I try to access that from the user control, it says the
> variable is not defined in the namespace. What am i missing!?!
> Alternatively, I could use a URL object to get the page were on directly in
> the usercontrol, but I couldnt find a URL method/property to give me just the
> file name.
> Hope all that makes sense!
> Cheers
>
> Dan
>
Hi,

Create an interface. eg:

public interface ICommonPage
{
int PageID{get;}
}

then implement it in the classes that contain the usercontrol in question
like this:

public class page1 : System.Web.UI.Page, ICommonPage
{
//Hardcode the value in a field:
int _PageID = 1; // or 2 in page2, 3 in page3, etc.

// The actual implementation:
public ICommonPage.PageID
{
get{return _PageID;}
}

// the rest of the class as it is...
}

And finally in the usercontrol cast the Page property to the interface and
get the value:

int PageID = ((ICommonPage)Page).PageID;

// work with PageID...

Hope this helps
Martin
"Dan Nash" <dan@.musoswire.co.uk> wrote in message
news:1D302C45-765A-46AE-AB82-631BB104CB6A@.microsoft.com...
> Hi
> I'm new to C#, moving from ASP, and slightly confused so bear with me!
> Basically I've got 4 pages, each of which runs the same user control (some
> header information). I want to be able to change the data in the user
control
> based on the page (everything else would be duplicated, hence the user
> control).
> Anyway, i thought the easiest way would be to use a variable set in the
> Page_load event of the calling page. So I've got a variable defined in my
> page class as..
> public int pageID = 1;
> However, when I try to access that from the user control, it says the
> variable is not defined in the namespace. What am i missing!?!
> Alternatively, I could use a URL object to get the page were on directly
in
> the usercontrol, but I couldnt find a URL method/property to give me just
the
> file name.
> Hope all that makes sense!
> Cheers
>
> Dan
Thanks guys!

Psychos post solved it, I guess you would say, the easy way! However,
Martin's solution looks interesting.. might try that one when I know a bit
more about C# (only got it Friday!).

Would there be any advantage with ICommonPage over the second method that
Psycho suggested?

Cheers guys

Dan

"Dan Nash" wrote:

> Hi
> I'm new to C#, moving from ASP, and slightly confused so bear with me!
> Basically I've got 4 pages, each of which runs the same user control (some
> header information). I want to be able to change the data in the user control
> based on the page (everything else would be duplicated, hence the user
> control).
> Anyway, i thought the easiest way would be to use a variable set in the
> Page_load event of the calling page. So I've got a variable defined in my
> page class as..
> public int pageID = 1;
> However, when I try to access that from the user control, it says the
> variable is not defined in the namespace. What am i missing!?!
> Alternatively, I could use a URL object to get the page were on directly in
> the usercontrol, but I couldnt find a URL method/property to give me just the
> file name.
> Hope all that makes sense!
> Cheers
>
> Dan
>