Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > User Control & member vars

Reply
Thread Tools

User Control & member vars

 
 
=?Utf-8?B?Sm9obks=?=
Guest
Posts: n/a
 
      08-19-2005
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


 
Reply With Quote
 
 
 
 
=?Utf-8?B?RGhhbmFuamF5YQ==?=
Guest
Posts: n/a
 
      08-19-2005
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
>
>

 
Reply With Quote
 
 
 
 
Karl Seguin
Guest
Posts: n/a
 
      08-19-2005
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" <> wrote in message
news:73216E01-7AE5-4C45-B984-...
>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
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Use self.vars in class.method(parameters, self.vars) caccolangrifata Python 18 07-22-2011 10:22 PM
How do I declare global vars or class vars in Python ? Linuxguy123 Python 7 02-20-2009 06:45 PM
app vars and cache vars Jon ASP .Net 3 12-14-2004 08:52 PM
How would I use qsort to sort a struct with a char* member and a long member - I want to sort in order of the long member Angus Comber C Programming 7 02-05-2004 06:41 PM
explicitly initialising member vars - necessary? Alex Hunsley Java 4 10-27-2003 04:51 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57