473,508 Members | 2,425 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Label Set on load returning null

2 New Member
Hi,
I am quite new to C#.NET and ASP and so it is likely that this is a very simple question. Basically I on a particular web form that I am creating a label's text is set on PAGE_LOAD, then basically when a user clicks a button I need to get the Text from this label, but it always returns null. Now I am guessing that this is something to do with the page lifecycle and the code behind not knowing that the label has been updated during the Page_Load but can't seem to see another way of getting this to work. However when I view the page, the lable actually displays that it has been updated with the correct text (not null). Here is a sample of the code.

protected void Page_Load(object sender, EventArgs e)
{
HttpRequest req = Context.Request;
sysName = req["system_list"];
removeLab.Text = sysName;
}

protected void Button1_Click1(object sender, EventArgs e)
{

String sysToDel = removeLab.Text;
HttpResponse res = Context.Response;
res.ClearContent();
res.Write("<html><head></head><body>");
res.Write(sysToDel);
res.Write(sysName); // Just thought I would try this...
res.Write("</body></html>");
res.Flush();
res.Close();
}

Note that the res.Write to the page is just to test to see whether I can get the Text required before completing the rest. Any help that you could give or tutorials that would explain where I am going wrong would be most appreciated. Thank you.
Oct 7 '07 #1
2 1404
kenobewan
4,871 Recognized Expert Specialist
Is the click event being called? Suggest you do some debugging.
Oct 7 '07 #2
JavaMonkey
2 New Member
Hi,
Yes I believe that it is. I have tried the below modified code and the page just displays "This is the string:" and no other information.

String sysToDel = removeLab.Text;
HttpResponse res = Context.Response;
res.ClearContent();
res.Write("<html><head></head><body>");
res.Write("This is the string: ");
res.Write(sysToDel);
res.Write(sysName); // Just thought I would try this...
res.Write("</body></html>");
res.Flush();
res.Close();

I have been searching since my first post and think that it maybe something to do with the ViewState now... though not 100%. Basically I think I may be able to save the viewstate of the Label and then get the Text from the stored Label view state?

I tried running through the Visual Studio debug and it looks like it goes through with no problems, but simply does not return the set Text of the label. i have tried a textbox and a hidden field, both yield the same results unless I change the text in the textbox, then I am displayed with the text, Very strange? Or maybe not if my understanding is incorrect.
Oct 7 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
4432
by: David McDivitt | last post by:
We have a massive java application to be made ADA compliant. We want onfocus and onblur events for each text field. The best way seems to be javascript, by cycling through all the nodes recursively...
2
5323
by: Razzie | last post by:
Hey all, I'm working on this project where I'm dynamically loading an assembly. Basically what I want is that I can just replace my old dll file with a new one without having to do anything...
0
1765
by: Giovane Calabrese | last post by:
ok. im try to make a multilanguage system based on that tutorial : http://www.123aspx.com/redir.aspx?res=29112 in my aspx pages all text are in labels , and i want to take the name labels...
3
1463
by: Christian Filzwieser | last post by:
Hy I created a WebControl called StatusBar with a static function public static void SetText(string text) { MyVariable = Text } and on Page Load I set MyVariable to the Label in my WebControl....
1
3735
by: bruce628 | last post by:
I want to use SWT Label and popmenu to construct a menubar ,and the effect of this menubar is same to the menubar in SWT.When click the Label,it should be highlighted and popmenu shows.The issue is...
1
2858
by: cnixuser | last post by:
Hello, I am having a problem that I believe is related to the way a stream reader object looks for a text file by default. What I am doing is using a StreamReader object to read the text of a text...
4
3313
RMWChaos
by: RMWChaos | last post by:
Darnit all, I expect the code I steal from others to work! =D Below is some code that I got to initiate multiple javascripts on page load (rather than using the "onload=" attribute). According the...
9
7983
by: =?Utf-8?B?RnJhbmsgVXJheQ==?= | last post by:
Hi all I have a MDI Container Form, with one label control on the Background of this container form. When I now open a child form, this form is behind the label ... and this looks ugly ... :-))...
3
4843
by: crjunk | last post by:
Hi Everyone, I have a web form that I would like to enhance. What I'd like to do is this: A user adds/edits the text in a textbox. I want the adjoining label to change color. Example: User...
0
7224
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
7118
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
7323
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
7379
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
5049
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
4706
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
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
415
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.