For Programmers: Free Programming Magazines  


Home > Archive > ASP .NET > October 2005 > Accessing literals with client side script?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Accessing literals with client side script?
Chris Ashley

2005-10-12, 8:05 am

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.

Grant Merwitz

2005-10-12, 8:05 am

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

"Chris Ashley" <chris.ashley2@gmail.com> wrote in message
news:1129112178.775982.252830@g44g2000cwa.googlegroups.com...
> 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.
>



Chris Ashley

2005-10-12, 8:05 am

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

Grant Merwitz

2005-10-12, 8:05 am

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 :))


"Chris Ashley" <chris.ashley2@gmail.com> wrote in message
news:1129113484.899165.128970@g14g2000cwa.googlegroups.com...
> 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
>



Chris Ashley

2005-10-12, 8:05 am

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

Chris

Bruce Barker

2005-10-12, 7:00 pm

it would be better to use:

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

which was designed for this purpose.

-- bruce (sqlwork.com)


"Grant Merwitz" <grant@workshare.com> wrote in message
news:O1RghuxzFHA.2540@TK2MSFTNGP09.phx.gbl...
> 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 :))
>
>
> "Chris Ashley" <chris.ashley2@gmail.com> wrote in message
> news:1129113484.899165.128970@g14g2000cwa.googlegroups.com...
>
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com