Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Request asp:label in code behind

Status
Not open for further replies.

raghu3

Programmer
Dec 19, 2005
96
US
I have the following sitituation:
aspx: form with

<asp:Label id="txtMoveTo" Font-Name="Arial"
Font-Size="8pt" runat="server"
EnableViewState="True" Text=" " />

The value is set via javascript based on other selections on the form.

Now I need to request this value in code-behind.

str1=Request.Form["txtMoveTo"].Trim();

Get the following error:
System.NullReferenceException: Object reference not set to an instance of an object

If I remove the trim, str1 is null ...
Pls advise



 
Did the old fashioned way:
Used a hidden variable that is set via javascript and Request this variable as labels are not posted back.
-R
 
No it does not work:
I set 2 different variables via the JS:

display the vaules in JS alert box:

1. when set: come up fine.

2. On click of Button: value of 1 button gets lost. Value is set on a seperate event: change of a text field.

I am so confused about the sequence.

Any advise ??

-raghu



 
raghu:
first thing, Request.Form will work ONLY for controls that are rendered as <input type... and <select> controls.

so how are label values preserved in DotNet? it uses the VIEWSTATE hidden field. the values in this can be changed ONLY server side.

therefore u have to use only hidden fields.

now to ur problem:
>> click of Button: value of 1 button gets lost. Value is set on a seperate event: change of a text field.

i dont understand much, could u be a bit more clear?


Known is handfull, Unknown is worldfull
 
Yes, as vbkris said you'll need someway of telling the server what the value is.

If you want to inform the user and the server, I'd suggest setting the value of the label and the value of a hidden input field via javascript.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top