473,480 Members | 1,918 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

User Control & member vars

I have a user control with 2 buttons on it & 1 label.... as each button is
pressed, they set a member variable within the class and sets the label
test.
I also have a get/set property for the member variable.
At Page_Load time I initialize this member variable

I have a host form which contains the user control
I have a button and a label on the host form (in addition to the user
control)
Now when I click the host-form button, it is suppose to get the property
from the user control and put the contents
into the host-form label.....

the following is from the user control:
private void Page_Load(object sender, System.EventArgs e)
{
mUC1Label= "this is from Page_Load";
}
public string UC1LinkButton
{
get { return mUC1Label; }
set {
mUC1Label = value;
uc1Label1.Text = mUC1Label;
}
}
private void LinkButton1_Click(object sender, System.EventArgs e)
{
UC1LinkButton = "LinkButton1_Click";
}
private void LinkButton2_Click(object sender, System.EventArgs e)
{
UC1LinkButton = "LinkButton2_Click";
}

on the host side:
void Button1_Click(object sender, System.EventArgs e)
{
ucTestLabel1.Text = "from the User Control Below " +
Webusercontrol12.UC1LinkButton;
}

ucTestLabel1 is a host-form control
now Button1_Click is not in the Code-Behind... it is in the form page (if
that makes a difference)

what shows up in ucTestLabel1 always is "this is from Page_Load" ,
never "LinkButton1_Click"; or "LinkButton2_Click";

why?

John
Nov 19 '05 #1
2 1376
The property in the User Control should store in view state to persist across
postbacks

public string UC1LinkButton
{
get {
if ( ViewState["UC1Text"]!=null)
return (string)ViewState["UC1Text"];
else
return string.Empty;
}
set {
ViewState["UC1Text"]=value;
}
}
"JohnK" wrote:
I have a user control with 2 buttons on it & 1 label.... as each button is
pressed, they set a member variable within the class and sets the label
test.
I also have a get/set property for the member variable.
At Page_Load time I initialize this member variable

I have a host form which contains the user control
I have a button and a label on the host form (in addition to the user
control)
Now when I click the host-form button, it is suppose to get the property
from the user control and put the contents
into the host-form label.....

the following is from the user control:
private void Page_Load(object sender, System.EventArgs e)
{
mUC1Label= "this is from Page_Load";
}
public string UC1LinkButton
{
get { return mUC1Label; }
set {
mUC1Label = value;
uc1Label1.Text = mUC1Label;
}
}
private void LinkButton1_Click(object sender, System.EventArgs e)
{
UC1LinkButton = "LinkButton1_Click";
}
private void LinkButton2_Click(object sender, System.EventArgs e)
{
UC1LinkButton = "LinkButton2_Click";
}

on the host side:
void Button1_Click(object sender, System.EventArgs e)
{
ucTestLabel1.Text = "from the User Control Below " +
Webusercontrol12.UC1LinkButton;
}

ucTestLabel1 is a host-form control
now Button1_Click is not in the Code-Behind... it is in the form page (if
that makes a difference)

what shows up in ucTestLabel1 always is "this is from Page_Load" ,
never "LinkButton1_Click"; or "LinkButton2_Click";

why?

John

Nov 19 '05 #2
this was double posted, and answered in the other post...take a look.

karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"JohnK" <Jo***@discussions.microsoft.com> wrote in message
news:73**********************************@microsof t.com...
I have a user control with 2 buttons on it & 1 label.... as each button is
pressed, they set a member variable within the class and sets the label
test.
I also have a get/set property for the member variable.
At Page_Load time I initialize this member variable

I have a host form which contains the user control
I have a button and a label on the host form (in addition to the user
control)
Now when I click the host-form button, it is suppose to get the property
from the user control and put the contents
into the host-form label.....

the following is from the user control:
private void Page_Load(object sender, System.EventArgs e)
{
mUC1Label= "this is from Page_Load";
}
public string UC1LinkButton
{
get { return mUC1Label; }
set {
mUC1Label = value;
uc1Label1.Text = mUC1Label;
}
}
private void LinkButton1_Click(object sender, System.EventArgs e)
{
UC1LinkButton = "LinkButton1_Click";
}
private void LinkButton2_Click(object sender, System.EventArgs e)
{
UC1LinkButton = "LinkButton2_Click";
}

on the host side:
void Button1_Click(object sender, System.EventArgs e)
{
ucTestLabel1.Text = "from the User Control Below " +
Webusercontrol12.UC1LinkButton;
}

ucTestLabel1 is a host-form control
now Button1_Click is not in the Code-Behind... it is in the form page (if
that makes a difference)

what shows up in ucTestLabel1 always is "this is from Page_Load" ,
never "LinkButton1_Click"; or "LinkButton2_Click";

why?

John

Nov 19 '05 #3

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

Similar topics

1
2739
by: user | last post by:
Sorry this must be really trivial, but I am new to Python... suppose I defined a=5 b=7 c=9 is there a command like usr_vars()
3
1241
by: Christopher J. Bottaro | last post by:
Hello, Lets say I have a class instance with the following member vars: var1, x, size. Now lets say I have dict with the following keys: var1, x, size. Is there an easy way to *automatically*...
1
1209
by: Paul Say | last post by:
Here is the seniaro, I have a user control consisting of a list of 3 Companies. e.g 1 - Company A 2 - Company B 3 - Company C - These are read from a data base and may increase in the future....
5
7642
by: Steve Richter | last post by:
In my user control I want to read the ViewState dictionary of the Parent control. But this sensible idea is not permitted by the compiler: Compiler Error Message: CS1540: Cannot access...
1
1903
by: John Keenan | last post by:
I have a user control with 2 buttons on it & 1 label.... as each button is pressed, they set a member variable within the class and sets the label test. I also have a get/set property for the...
3
1439
by: Sambo | last post by:
By accident I assigned int to a class member 'count' which was initialized to (empty) string and had no error till I tried to use it as string, obviously. Why was there no error on assignment( near...
0
2492
by: stevenhaochen | last post by:
I add a user control (a simple textbox control) to customize datagridview column to test how to add user control to datagridview. I found a weired behavior. I can not input "q", "!", "#". But I...
9
1969
by: David | last post by:
With a non-server app there is one instance of the program running and one user 'using' it at a time. With this scenario I'm pretty comfortable with variable scope and lifetime. With a server app...
2
1718
by: empiresolutions | last post by:
I'm using the following AJAX code to send GET vars to my processing PHP file. This works great as is except that it will not accept a *&* (AND symbol) in the text input. It trys to pass what is after...
0
7037
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,...
0
7076
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...
1
6730
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
5321
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,...
1
4767
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...
0
4471
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...
0
1294
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 ...
1
558
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
174
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...

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.