Accessing literals with client side script?

C

Chris Ashley

Is there any way to access hidden literal controls using client side
script? Can't seem to see them at all in the HTML output.
 
G

Grant Merwitz

no, when you make some visible=false in your code, it doesn't even arrive
client side.
You want to use an HtmlControl that you can hide, and JavaScript will be
able to see that.

If its not in the HTML output, then JavaScript cannot see it as it doesn't
exist client side
 
C

Chris Ashley

Hi Grant,

Thanks for your help on both points. I find that it's difficult trying
to think about a stateless environment in OO terms!

I'm probably using the literal control totally wrong - basically my
page class has 'pageNumber' int which I was populating a hidden literal
with in the hope that I could access it using client side script. Is
there a better alternative? Any way to populate a hidden form field
using server controls?

Thanks,

Chris
 
G

Grant Merwitz

yes, if you create a an html control (like say <input> and set its style to
be visibility:hidden
You can set this control to runat server:

<input type="textbox" id="tb" style="visibility:hidden" runat="server"/>

You can now declare this in your code behind and sets its value.
This will also be retrievable through the JavaScript

code behind:
protected System.Web.UI.HtmlControls.HtmlInputText tb;

then
tb.Value = "Your ID Goes here";

this you should now be able to see in your source, but it will be invisible
on the page.

HTH (still pending on your other question .. gotta do my job :))
 
C

Chris Ashley

Aha! Didn't realise that was possible at all. Thanks ever so much for
that. :)

Chris
 
B

Bruce Barker

it would be better to use:

<input type=hidden id=tb runat=server>

which was designed for this purpose.

-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top