I have a page that has a code behind file that is looking very messy. I
would like to put some of the code in a class library to clean up the page
but I can't get the syntax correct for referring to controls like buttons on
the from functions in the class library.
What would be the correct syntax to do this?
Any help is greatly appreciated. 9 1542
Hi Greg,
Your idea sounds like a good one, only problem is we need to see some
code to see where it's going wrong. For a guess, I'd say that for
starters, your class lib project needs to reference System.Web, and
also import the namespaces such as System.Web.UI.WebControls.
Greg Smith wrote:
I have a page that has a code behind file that is looking very messy. I
would like to put some of the code in a class library to clean up the page
but I can't get the syntax correct for referring to controls like buttons on
the from functions in the class library.
What would be the correct syntax to do this?
Any help is greatly appreciated.
Thank you for your response.
Your idea sounds like a good one, only problem is we need to see some
code to see where it's going wrong.
Here is my code.
The calling page:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
Class1 cl = new Class1();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnCaller_Click(object sender, EventArgs e)
{
cl.ReLabel_button(this);
}
}
The class file:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public class Class1
{
public Class1()
{
}
public void ReLabel_button(Page pg)
{
pg.btnCaller.Text = "Hello World!";
}
}
Thanks for posting the code. The issue is that the input parameter to
ReLabel_button is of type Page. This means that your passed-in Page
object is subclassed to type Page from type _Default. btnCaller,
however, is only available on type _Default, not type Page. Therefore,
it is not visible within the method.
An easier way to do this is to have the method take a parameter of type
Button, and just pass in btnCaller.
Greg Smith wrote:
Thank you for your response.
Your idea sounds like a good one, only problem is we need to see some
code to see where it's going wrong.
Here is my code.
The calling page:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
Class1 cl = new Class1();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnCaller_Click(object sender, EventArgs e)
{
cl.ReLabel_button(this);
}
}
The class file:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public class Class1
{
public Class1()
{
}
public void ReLabel_button(Page pg)
{
pg.btnCaller.Text = "Hello World!";
}
}
"KJ" <n_**********@mail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
Thanks for posting the code. The issue is that the input parameter to
ReLabel_button is of type Page. This means that your passed-in Page
object is subclassed to type Page from type _Default. btnCaller,
however, is only available on type _Default, not type Page. Therefore,
it is not visible within the method.
An easier way to do this is to have the method take a parameter of type
Button, and just pass in btnCaller.
Rat farts!
Actually ther are about 30 controls. I was hoping to pass just the page.
>
Greg Smith wrote:
>Thank you for your response.
Your idea sounds like a good one, only problem is we need to see some
code to see where it's going wrong.
Here is my code.
The calling page: using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page { Class1 cl = new Class1();
protected void Page_Load(object sender, EventArgs e) {
} protected void btnCaller_Click(object sender, EventArgs e) { cl.ReLabel_button(this); } }
The class file:
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls;
public class Class1 { public Class1() {
} public void ReLabel_button(Page pg) { pg.btnCaller.Text = "Hello World!"; } }
You can pass the page. Just change the method signature to
ReLabel_button(_Default pg)
Greg Smith wrote:
"KJ" <n_**********@mail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
Thanks for posting the code. The issue is that the input parameter to
ReLabel_button is of type Page. This means that your passed-in Page
object is subclassed to type Page from type _Default. btnCaller,
however, is only available on type _Default, not type Page. Therefore,
it is not visible within the method.
An easier way to do this is to have the method take a parameter of type
Button, and just pass in btnCaller.
Rat farts!
Actually ther are about 30 controls. I was hoping to pass just the page.
Greg Smith wrote:
Thank you for your response.
Your idea sounds like a good one, only problem is we need to see some
code to see where it's going wrong.
Here is my code.
The calling page:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
Class1 cl = new Class1();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnCaller_Click(object sender, EventArgs e)
{
cl.ReLabel_button(this);
}
}
The class file:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public class Class1
{
public Class1()
{
}
public void ReLabel_button(Page pg)
{
pg.btnCaller.Text = "Hello World!";
}
}
You can pass the page. Just change the method signature to
ReLabel_button(_Default pg)
I'm not sure I follow.
So the code should look like ....
public partial class _Default : System.Web.UI.Page
{
Class1 cl = new Class1();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnCaller_Click(object sender, EventArgs e)
{
cl.ReLabel_button(_Default pg);
}
}
public class Class1
{
public Class1()
{
}
public void ReLabel_button(Page pg)
{
<Something something>.Text = "Hello World!";
}
}
Not quite. Code the method like this:
public void ReLabel_button(_Default pg)
{
///your code here
}
Then, call it like this:
cl.ReLabel_button(pg); //here, keep in mind that pg is of type _Default
Greg Smith wrote:
You can pass the page. Just change the method signature to
ReLabel_button(_Default pg)
I'm not sure I follow.
So the code should look like ....
public partial class _Default : System.Web.UI.Page
{
Class1 cl = new Class1();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnCaller_Click(object sender, EventArgs e)
{
cl.ReLabel_button(_Default pg);
}
}
public class Class1
{
public Class1()
{
}
public void ReLabel_button(Page pg)
{
<Something something>.Text = "Hello World!";
}
}
I still have something wrong. Possibly to do with your "//here, keep in
mind that pg is of type _Default " statement.
My code now looks like this.
public partial class _Default : System.Web.UI.Page
{
Class1 cl = new Class1();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnCaller_Click(object sender, EventArgs e)
{
cl.ReLabel_button(pg); //here, keep in mind that pg is of type
_Default
}
}
public class Class1
{
public Class1()
{
}
public void ReLabel_button(_Default pg)
{
///your code here
}
}
The code:
//here, keep in mind that pg is of type _Default
Is just a comment. You can delete it.
Greg Smith wrote:
I still have something wrong. Possibly to do with your "//here, keep in
mind that pg is of type _Default " statement.
My code now looks like this.
public partial class _Default : System.Web.UI.Page
{
Class1 cl = new Class1();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnCaller_Click(object sender, EventArgs e)
{
cl.ReLabel_button(pg); //here, keep in mind that pg is of type
_Default
}
}
public class Class1
{
public Class1()
{
}
public void ReLabel_button(_Default pg)
{
///your code here
}
}
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: DC Gringo |
last post by:
I have an myPage.aspx with a myPage.ascx user control. The user control is
the main header of the page. I have some conditional case code in the user
control that I use which depends on a public...
|
by: martin |
last post by:
Hi,
I am a web page and a web user control. My web user control is placed in my
web page using the following directive
<%@ Register TagPrefix="uc1" TagName="Header"...
|
by: John Lau |
last post by:
Hi,
Is there documentation that talks about the page lifecycle, the lifecycle of
controls on the page, and the rendering of inline code, in a single
document?
Thanks,
John
|
by: Mikey_Doc |
last post by:
Hi
We are running cms 2002, Framework 1.0 with Visual studio 2002. We
have just upgraded to Framework 1.1 and visual studio 2003.
All of our database connection strings are stored within the...
|
by: Amelyan |
last post by:
I am struggling here trying to determine what is a good programming practice
as far as referencing your URLs.
When you use Response.Redirect, do you use
1) Hard-coded string --...
|
by: TWEB |
last post by:
I think I may have an IIS / ASP.Net Configuration issue that I need some
guidance with resolving.
Here's the problem:
a) I have a .stm file.
b) I referenc a .aspx file on this .stm file using a...
|
by: Alex Maghen |
last post by:
I want to create a utility function that will seach the current page for one
of my UserControls by it's type. So, let's say that I have a UserControl
whose class I defined as follows:
namespace...
|
by: cmd |
last post by:
I have code in the OnExit event of a control on a subform. The code
works properly in this instance. If, however, I put the same code in
the OnExit event of a control on a Tab Control of a main...
|
by: =?Utf-8?B?SmFtZXMgUGFnZQ==?= |
last post by:
Hi all
I have a user control - mycontrol.ascx with various controls within it.
mycontrol.ascx is utilised in myPage.aspx
I have a class (class1) to carry out various functions, subs etc.
How...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |