473,799 Members | 2,786 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.TextBo x.Text = "Fred";

Any help is greatly appreciated.
Nov 18 '05 #1
5 1256
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******** ******@TK2MSFTN GP10.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.TextBo x.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******** ******@TK2MSFTN GP10.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.TextBo x.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.W ebControls.Text Box 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******** ******@TK2MSFTN GP10.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.TextBo x.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(contain ed 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.T ext = ....

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.P age
{
protected System.Web.UI.W ebControls.Text Box 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 GetPageTextBoxV alue(Page page, string property)
{
string value = (string)DataBin der.Eval(page,p roperty);
page.Response.W rite("<br>"+pro perty +": " + 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.P age as above one,

In class module , we define the method like:
public static void GetPageTextBoxV alue(WebForm1 page)
{
string value = page.txtA.Text;
page.Response.W rite("<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
3223
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 far so good. But when I want to execute, it askes to "set project main class". The only option it displays is the default project. But the "okay" button won't highlight. I cannot select anything else, nor can I roam directories to select
27
2399
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. It is available at: http://staff.washington.edu/sabbey/py_do Good background on thunks can be found in ref. . Simple Thunks
2
1736
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 Trimbitas Sorin
6
1475
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 One change I had to make, relative to what I had working in MySQL, was
14
5907
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
1248
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 expert of them, that putting a little star* above an item makes it accept the argument as a list. But when I tried this, I got an invalid syntax error message.
27
2862
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
5825
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: _________________________________________________________________ /* Simple Thread Object ______________________________________________________________*/ #include <pthread.h> extern "C" void* thread_entry(void*);
6
1709
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 the first, fifth and eighth element I might do something like this: b = a(); I can't seem to figure out a similar Python construct for selecting specific indices. Any suggestions?
0
9687
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9543
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10237
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7567
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6808
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4144
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3761
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.