0

I use the code line below in a javascript function to get a textbox value. Is there anyway to grab a session value instead. So like replace LastNameTextBox.ClientID with Session("LastName") etc.?

var LastNameTextBox = document.getElementById('<%= LastNameTextBox.ClientID %>');

Then I use the following to add it to a pdf.

   printWindow.document.write('Last Name:');
0

1 Answer 1

3

It would be exactly the same but with Session("LastName") instead of LastNameTextBox.ClientID), e.g.:

printWindow.document.write('Last Name: <%= Session("LastName") %>');

...although you may want to make sure the name is escaped correctly, since names can contain ' characters (amongst other things), which if unescaped would cause an error in the script when it went to the client browser, because the browser would see:

printWindow.document.write('Last Name: O'Toole');
// Syntax error -------------------------^

If you're using .Net 3.5 or later, you can use JavaScriptSerializer to do the escaping for you.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.