473,396 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Read/Write controls on aspx page from class code (vb.net)

I suspect this is easy, but I have been stumped for a day trying to solve this..

I want to be able to have an unlimited number of aspx pages that all use the code in one class file. I want code in that class file to be able to read and write the controls on the aspx pages. For example, on all the aspx pages, I'll have a label named label1. From code in the class file, I want to be able to do something like label1.text = "hello world

I know about httpcontext, and can now do _context.response.write("hello world"), but I want a general solution that works with labels and other standard server controls, and is generic so that I can add more aspx pages later without having to change the class file that provides the code

Please give a complete example if possible, showing what I need to put in the aspx pages and what I need to put in the class file. There are dozens of posts about this subject on UseNet, but none that assume my limited background knowledge

Thanks

ps - i'm posting this twice... the second time with my MSDN subscriber email, to get a promised 48 hour response... sorry, I didn't have my email assigned earlier.
Nov 18 '05 #1
9 2934
Hi

I don't know any C#. Do you have an example in vb.net

Are you saying that the code in the class file needs to know up front the names of all the aspx pages that may call it? This is not ideal, but not a huge problem. But would it be OK to have 100 aspx pages use the same class code? I have to say, my feeling is that there is some way to make a generic solution, so I can have a million unknown aspx pages all use the same class code. I really, really prefer a generic solution. Remember, these aspx pages will have the same server controls on them, with the same names for each control

Thanks

----- Steven Cheng[MSFT] wrote: ----

Hi

From your description, you'd like to operate a certain aspx page's control
member in a component class. And it need to meet with many pages,yes

As for this problem, here is some of my suggestions
1. If you'd like to retrieve the Page's instance of the current processed
asp.net page. You may use the following code in the component

public static void ComponentMethod(

SimplePage sp = (SimplePage)HttpContext.Current.Handler
sp.Text1 = "Text Value1"
sp.Text2 = "Text Value2"
sp.Text3 = "Text Value3"
#Simple Page is the Codebehind class of the certain aspx page.

If you want to retrieve the page's certain Control member, you need to
change its scope declaration to "public" because by default control member
is defined a s "protected". For example

protected System.Web.UI.WebControls.TextBox TextBox1
#change the "protected" to "public

or you can define a public property for the pageclass to wrapper the
control member, such as
public string Text

ge

return TextBox1.Text

se

TextBox1.Text = value

So that you can retrive it and modify it in the certain component as I
mentioned above.

In addition, the means I mentioned above is based on that we know how many
pageclasses we have and write the component's code according to the page
class and you need to define the public properties in the
page classes. If there are many different pageclasses and the component
want to have no infos on those page classes, I'm afraid this way not work.
Do you think so
Regards

Steven Chen
Microsoft Online Suppor

Get Secure! www.microsoft.com/securit
(This posting is provided "AS IS", with no warranties, and confers no
rights.

Get Preview at ASP.NET whidbe
http://msdn.microsoft.com/asp.net/whidbey/default.asp




Nov 18 '05 #2
Hi,

Thanks for the followup. Not simply the front the names but the page's
codebehind class. We need to operate a class's instance according to its
class, yes? Also, its ok to have many pages share one page class, but
that'll cause many problem since we can't make so many pages completely
have same features. One ideas is to have a master page(a common page class
for all the pages) so that all the page class derived from the base page
class which contains the common features need to be operated in the common
component. Do you think so?

In addtion, below is certain website which can help translate C# code into
VB.NET. I believe it'll be helpful to you.
http://authors.aspalliance.com/aldot...translate.aspx

Thanks.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #3
Hi,

From your description, you'd like to operate a certain aspx page's control
member in a component class. And it need to meet with many pages,yes ?

As for this problem, here is some of my suggestions:
1. If you'd like to retrieve the Page's instance of the current processed
asp.net page. You may use the following code in the component:

public static void ComponentMethod()
{
SimplePage sp = (SimplePage)HttpContext.Current.Handler;
sp.Text1 = "Text Value1";
sp.Text2 = "Text Value2";
sp.Text3 = "Text Value3";
}

#Simple Page is the Codebehind class of the certain aspx page.

If you want to retrieve the page's certain Control member, you need to
change its scope declaration to "public" because by default control member
is defined a s "protected". For example:

protected System.Web.UI.WebControls.TextBox TextBox1;
#change the "protected" to "public"

or you can define a public property for the pageclass to wrapper the
control member, such as
public string Text1
{
get
{
return TextBox1.Text;
}
set
{
TextBox1.Text = value;
}
}

So that you can retrive it and modify it in the certain component as I
mentioned above.

In addition, the means I mentioned above is based on that we know how many
pageclasses we have and write the component's code according to the page
class and you need to define the public properties in the
page classes. If there are many different pageclasses and the component
want to have no infos on those page classes, I'm afraid this way not work.
Do you think so?
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx



Nov 18 '05 #4
Hi

I don't know any C#. Do you have an example in vb.net

Are you saying that the code in the class file needs to know up front the names of all the aspx pages that may call it? This is not ideal, but not a huge problem. But would it be OK to have 100 aspx pages use the same class code? I have to say, my feeling is that there is some way to make a generic solution, so I can have a million unknown aspx pages all use the same class code. I really, really prefer a generic solution. Remember, these aspx pages will have the same server controls on them, with the same names for each control

Thanks

----- Steven Cheng[MSFT] wrote: ----

Hi

From your description, you'd like to operate a certain aspx page's control
member in a component class. And it need to meet with many pages,yes

As for this problem, here is some of my suggestions
1. If you'd like to retrieve the Page's instance of the current processed
asp.net page. You may use the following code in the component

public static void ComponentMethod(

SimplePage sp = (SimplePage)HttpContext.Current.Handler
sp.Text1 = "Text Value1"
sp.Text2 = "Text Value2"
sp.Text3 = "Text Value3"
#Simple Page is the Codebehind class of the certain aspx page.

If you want to retrieve the page's certain Control member, you need to
change its scope declaration to "public" because by default control member
is defined a s "protected". For example

protected System.Web.UI.WebControls.TextBox TextBox1
#change the "protected" to "public

or you can define a public property for the pageclass to wrapper the
control member, such as
public string Text

ge

return TextBox1.Text

se

TextBox1.Text = value

So that you can retrive it and modify it in the certain component as I
mentioned above.

In addition, the means I mentioned above is based on that we know how many
pageclasses we have and write the component's code according to the page
class and you need to define the public properties in the
page classes. If there are many different pageclasses and the component
want to have no infos on those page classes, I'm afraid this way not work.
Do you think so
Regards

Steven Chen
Microsoft Online Suppor

Get Secure! www.microsoft.com/securit
(This posting is provided "AS IS", with no warranties, and confers no
rights.

Get Preview at ASP.NET whidbe
http://msdn.microsoft.com/asp.net/whidbey/default.asp




Nov 18 '05 #5
Hi,

Thanks for the followup. Not simply the front the names but the page's
codebehind class. We need to operate a class's instance according to its
class, yes? Also, its ok to have many pages share one page class, but
that'll cause many problem since we can't make so many pages completely
have same features. One ideas is to have a master page(a common page class
for all the pages) so that all the page class derived from the base page
class which contains the common features need to be operated in the common
component. Do you think so?

In addtion, below is certain website which can help translate C# code into
VB.NET. I believe it'll be helpful to you.
http://authors.aspalliance.com/aldot...translate.aspx

Thanks.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #6
Hi Steve

Thank you for trying to help solve my problem

However, I am completely confused by your replies. They are much too complicated for me to understand. For example:

"One ideas is to have a master page(a common page class
for all the pages) so that all the page class derived from the base page
class which contains the common features need to be operated in the common
component.

I have no idea how to "derive from the page base class

What I need is a vb.net example that is complete. That is, I need every line of code in the aspx page, every line of code in the code behind for that aspx page, and every line of code in the class file that I will use to "power" the aspx page and the other aspx pages that will have the same web controls on them, but will have a different page layout and graphics

The example can be very, very simple. Just a 'hello world' example is fine. So, one label on the aspx page. Then, read and write the text value for that label from the class file

I appreciate that I should be able to understand your answers already, but I just don't. I have hundreds of dollars of Wrox asp.net books, and have read them over and over. I have never seen this simple question answered. I am sorry for being such a pain, but I am really, really stumped, and have burned a solid week on what will probably turn out to be a three minute answer for someone who knows the answer

Best Regards, and thank you

PS - VB.NET code please! I don't know C#.
Nov 18 '05 #7
Hi,

Have you had a chance to check the demo in my last reply or have you got
any further ideas on this issue? If you have anything else we can help,
please feel free to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #8
Hi Steve

I was able to make use of the sample you created, with one important change. I had to chang

Dim sp As SimplePage = HttpContext.Current.Handler

to

Dim sp As Object = HttpContext.Current.Handle

If I didn't make this change, then I could only use the PageUtil.vb code from the aspx page entitled SimplePage. The whole goal of my original question was to be able to call PageUtil code from any arbitrary aspx page, and read and write control values on such aspx pages from the PageUtil code

I suspect that by subtituting 'Object' for 'SimplePage' that I have changed from early binding to late binding. Is there a way around this? How long does it take to process a late binding vs an early binding? I know it's longer, but it still seems to happen in an instant, so I am inclined to just leave it alone

This is the first time I have used the managed newsgroups, and I must say I am VERY impressed so far. Thank you so much
Nov 18 '05 #9
Hi,

Thanks very much for your response. I feel glad that my suggestion has
helped you. As for the problem you mentiond:
=====================
I was able to make use of the sample you created, with one important
change. I had to change

Dim sp As SimplePage = HttpContext.Current.Handler
to
Dim sp As Object = HttpContext.Current.Handler
=======================

I think this is because you haven't referenced the certain page class( the
"SimplePage" ) in our utility class. Thus, the SimplePage class become
invisible in the utility class(also no intellisense). If we want to use
early binding to access a class's members or interfaces , we need to
reference the class's assemblie in the caller's our caller class's
project. Does this answer or question?

If you still have anything unclear, please feel free to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #10

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

Similar topics

7
by: Cliff Cavin | last post by:
How do I programatically change the background color of an aspx page in code? Is there something like Page.BgColor = "#FFFFFF" ? For that matter, how do I access any of the DOCUMENT...
5
by: JohnSmith | last post by:
I suspect this is easy, but I have been stumped for a day trying to solve this.. I want to be able to have an unlimited number of aspx pages that all use the code in one class file. I want code...
4
by: GMartin | last post by:
Are there any significant stopping blocks from taking an ASPX Page someone designs in VB.NET, and redoing the Code behind page to use C#? Is the Code behind the only thing one would need to...
3
by: Shapper | last post by:
Hello, How to I create add Div with an Asp:Label and an Asp:DropDownList inside it to my aspx page from my vb.net code? Thanks, Miguel
0
by: satheeshkumarr | last post by:
Is it Possible to call a .aspx page from a .NET webservice? If possible, Please help me out. Thanks in Advance, Satheesh
1
by: yanni | last post by:
Hello, I'm creating asp.net 2.0 web site app, I tried to use ¡°ObjectIssue.Page1¡± as TypeName of ObjectDataSource, received error message ¡°The type specified in the TypeName property of...
1
by: mahesh singh | last post by:
Hi Everyone, I am a new joinee to this site. Need help regarding a particular problem. I dont have much experience as a .net developer (1 year) and m hoping that somebody here wud b able to help...
2
by: 111111222222 | last post by:
I have a grid view with a SSN column as a hyperlink. Whenever I click SSN I want to populate grid view in same page for that particular SSN. For this I need to pass SSN from aspx page to code...
2
by: visweswaran2830 | last post by:
I want to know to get content(in IE "View->Source" that produce current page content) of current aspx page in asp.net..
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.