Moving data from Javascript to VB.NET

Buho1

Member
Joined
Mar 23, 2006
Messages
12
Location
Maryland, USA
Programming Experience
10+
Hi all. I have a very strange question, I'm not sure how to search on it (I have been searching the net for the past several hours).

I have an ASP.NET label that I set the Text property to "<INPUT type=""hidden"" id=""pnlX"">50</INPUT>"

Now, I also have some Javascript that gets this data very easily and uses it correctly. When it's done, it puts a new value back into this hidden field. The problem is VB.NET, OnPostBack, doesn't see the change in the label. I think it's getting it's Text value from VIEWSTATE. Fine. I have Plan B.

Plan B: I want to access the incoming data stream from the POST event when the form was submitted to the webserver. Here's my problem: I have no clue where this input stream is in the .NET framework. Can someone direct me to how I can access it? I'm thinking something like Me.Request....

This is a strange request. How do you move data generated by JavaScript back to VB.NET? Any help much appreciated!

Oh yeah, I'm trying to avoid visible text fields for GUI reasons only, not security reasons (the data itself is non-critical GUI-releated).
 
1st off, you haven't an ASP.NET label (System.Web.UI.WebControls.Label) but rather HTML hidden control.

2nd off, the element INPUT doesn't require a closing tag closing but rather you suppose to add a name inside the tag i.e.
VB.NET:
<[I] INPUT id="pnlX" type="hidden" value="50" name="myControl" [/I]>

3rd off, ASP.NET is server-side code unlike JS (and that's why you have to proceed it to server if you want to avoid using of JS)

Finally this is how you can get value of hidden control with vb.net.
for instance if you want to pass value of myControl to label1 then you suppose to request the control by its name (very simple if i may)
VB.NET:
[SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Label1.Te[/SIZE]xt = Request.Form("myControl")

HTH
Regards ;) wellcome to the forum :)


 
Hey Kulrom.

First off, yes, I know this. I initially thought it strange that labels weren't updated like textboxes, but only form elements are sent back to the browser (including Viewstate).

Second off, my mistake. I wrote that on the fly in the forum. My code doesn't generate that syntax error.

Third off, I completely understand this and thought I reflected that in my original post. Perhaps I wasn't clear.

Finally, Me.Request.Form("myControl") was exactly what I needed! Thank you so much! Strange that Form doesn't pick up the id= in the form, but no big, I added name= to my label.

My app works beautifully now. I needed DHTML elements to carry through over postbacks and this works like a charm! Thanks again! I've been browsing around at other posts; this is a nice forum.
 
Back
Top