473,396 Members | 1,996 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.

A simple syntax question

I am sure this is very simple but I can't seem to get the syntax correct.

I have a class that I added to my application and I would like to reference
controls on a webform. Something like:

WebForm1.TextBox.Text = "Fred";

Any help is greatly appreciated.
Nov 18 '05 #1
5 1242
Unless this is your CodeBehind class you are talking about, I think you are
trying to break all rules of object orientated programming. :-) Better
solution, create a function in this class, that takes in values from your
codebehind class, and returns what you want, then call this function from
your codebehind to set the value.

"Greg Smith" <gj*@umn.edu> wrote in message
news:u4**************@TK2MSFTNGP10.phx.gbl...
I am sure this is very simple but I can't seem to get the syntax correct.

I have a class that I added to my application and I would like to reference controls on a webform. Something like:

WebForm1.TextBox.Text = "Fred";

Any help is greatly appreciated.

Nov 18 '05 #2
is "TextBox" a server-side control? if not you can't.

<asp:TextBox id="text1" runat="server"></asp:TextBox>

text1.Text = "this is a test";
--
Curt Christianson
Owner/Lead Developer, DF-Software
www.Darkfalz.com
"Greg Smith" <gj*@umn.edu> wrote in message
news:u4**************@TK2MSFTNGP10.phx.gbl...
I am sure this is very simple but I can't seem to get the syntax correct.

I have a class that I added to my application and I would like to reference controls on a webform. Something like:

WebForm1.TextBox.Text = "Fred";

Any help is greatly appreciated.

Nov 18 '05 #3
Assume you mean from your codebehind file.

Make sure you have the TextBox declared in your codebehind file....

Assuming your control is called txtBox1

protected System.Web.UI.WebControls.TextBox txtBox1;

then from within your Page_Load event you would have :

txtBox1.Text = "Fred";

You shouldn't reference the form from the server side code (assume that is
what you are trying to do with WebForm1 below).

Matt
http://www.3internet.com

"Greg Smith" <gj*@umn.edu> wrote in message
news:u4**************@TK2MSFTNGP10.phx.gbl...
I am sure this is very simple but I can't seem to get the syntax correct.

I have a class that I added to my application and I would like to reference controls on a webform. Something like:

WebForm1.TextBox.Text = "Fred";

Any help is greatly appreciated.

Nov 18 '05 #4
Hi Mark,
Thanks for posting in the community!
From your description, you'd like to get some suggestions on how to refer a
certain control(contained in a web page)'s value from a class module,yes?
If there is anything I misunderstood, please feel free to let me know.

As for this problem, here are my suggestions:
Generally, in a ASP.NET web page's code-behind class file, if you want to
get a webcontrol(such as textbox) 's value, you could use the code as:
this.TextBox1.Text = ....

However, if we want to retreive a certain page's sub control 's value in a
certain class module, we could use the following two means:
1. define a property for the page class which delegate the certain
webcontrol member, then in the class module, you can get the page's control
's value via the public property. For example:

public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox txtA;

public string TextA
{
get{return txtA.Text;}
set{txtA.Text = value;}
}

.............
}

Then we can define a method in the class module to get the property's value
from a certain page, just like:
public static void GetPageTextBoxValue(Page page, string property)
{
string value = (string)DataBinder.Eval(page,property);
page.Response.Write("<br>"+property +": " + value);
}

2. If you'd like to directly access the certain control's value via its
control's Id, you can pass the certain page class's instance into the class
module's method and do any operations on it. For example:
Still use the
public class WebForm1 : System.Web.UI.Page as above one,

In class module , we define the method like:
public static void GetPageTextBoxValue(WebForm1 page)
{
string value = page.txtA.Text;
page.Response.Write("<br>txtA.Text: " + value);
}

Thus, it'll looks much simpler.

Please check out my suggestions. If you feel anything unclear, please feel
free to let me know.

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.)

Nov 18 '05 #5
Hi Mark,
Have you had a chance to try out my suggestions or have you got any further
ideas on this issue? If you have any quesions, please feel free to let me
know.

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.)

Nov 18 '05 #6

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

Similar topics

10
by: martin | last post by:
Hello, I just got the SUN Java IDE. (Netbeans IDE 3.5.1) Very very nice, and I worked myself through the tutorial (about making a colorswitch). Now, When I compile it gives no errors at all. So...
27
by: Brian Sabbey | last post by:
Here is a first draft of a PEP for thunks. Please let me know what you think. If there is a positive response, I will create a real PEP. I made a patch that implements thunks as described here....
2
by: Trimbitas Sorin | last post by:
Hello I have a simple syntax question : What does the following line mean: 1: %checkType; ?? I know that @test="" is an array and $test="" is a simple variable. Thank you With best regards...
6
by: Ted | last post by:
Here is one such function: CREATE FUNCTION my_max_market_date () RETURNS datetime BEGIN DECLARE @mmmd AS datetime; SELECT max(h_market_date) INTO @mmmd FROM holdings_tmp; RETURN @mmmd; END ...
14
by: dba_222 | last post by:
Dear experts, Again, sorry to bother you again with such a seemingly dumb question, but I'm having some really mysterious results here. ie. Create procedure the_test As
5
by: Hakusa | last post by:
I have the argument items in my class room. class room: def __init__(self, name, description, items*): I thought I remembered from a tutorial I read once, and I've read so many I feel like an...
27
by: Paulo da Silva | last post by:
Hi! I was told in this NG that string is obsolet. I should use str methods. So, how do I join a list of strings delimited by a given char, let's say ','? Old way:
17
by: Chris M. Thomasson | last post by:
I use the following technique in all of my C++ projects; here is the example code with error checking omitted for brevity: _________________________________________________________________ /*...
6
by: Eric | last post by:
I'm learning Python (while coming from MATLAB). One question I have is that if I have a list with say 8 elements, and I want just a few of them how do I select them out. In MATLAB, if I just want...
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: 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: 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
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
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...
0
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,...

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.