GetElementByID

T

tshad

I am trying to access my textbox in javascript but I can't seem to do it by
the ID set up in my aspx page: ID = MyText.

I can access it this way:

function ClipBoardTest() {

var txt = document.getElementById('ctl00$ContentPlaceHolder1$MyText');

window.clipboardData.setData("Text", txt.value);

}

Is there an easier way to get to it? I don't know what the name will be
since it could be different on different pages.

Thanks,

Tom
 
T

tshad

Found out how to do this:

var txt = document.getElementById("<%= MyText.ClientID %>");

But this seems to only work if the tag is visible.

I am trying write my string (which is very long) to the clipboard by writing
it to a textbox and then copying to the clipboard using the code below.

But I don't want the textbox to show on the screen.

If I do:

<asp:TextBox ID="MyText" TextMode="MultiLine" Visible="false" runat="server"
/>

It can't find it. I assume this is because it doesn't get rendered to the
page.

How would I do this?

Thanks,

Tom
 
S

Scott M.

Is there a limit to the amount this field can hold?

With traditional HTML forms, you can submit form data via GET or POST.
Since data sent via GET is appended to the URL and most browsers limit a
URL's length, then the answer is "yes, there is a limit", but only when GET
is used.

ASP.NET forms submit their data with a POST, which sends the data in the
background as a stream. There is no limit to how long that stream could be,
but obviously, the longer the stream, the longer it will take to send the
data. Hidden form fields are the basis behind the ASP .NET principle of
ViewState, which every ASP .NET page has. ViewState is just an
automatically generated hidden form field that has its data compacted with
an encoding scheme.

-Scott
 
T

tshad

Scott M. said:
With traditional HTML forms, you can submit form data via GET or POST.
Since data sent via GET is appended to the URL and most browsers limit a
URL's length, then the answer is "yes, there is a limit", but only when
GET is used.
I don't understand here. Are you saying the hidden form would be in the URL
if you were doing a Get????

If that were the case, I couldn't use a hidden field for this use.

Thanks,

Tom
 
S

Scott M.

tshad said:
I don't understand here. Are you saying the hidden form would be in the
URL if you were doing a Get????

Yes. All form data is sent to the destination (the form's ACTION attribute
value) as a querystring appended to the URL when a form is submitted via
GET. Do a Google search on anything and take a close look at the URL after
your search returns its results to see what I mean.
If that were the case, I couldn't use a hidden field for this use.

Yes, you could, because in ASP .NET, forms are submitted via POST, which
means that the data would NOT be added to the URL and there is no length
restriction.

-Scott
 

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,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top