Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Get Textbox values

  Asked By: Holly    Date: Apr 06    Category: Sharepoint    Views: 2938

I have created a webpart with embedded script
("javascript"). Now I'd like to assign the values of
my textbox to the embedded script particularly to the
values of my string variables but I don't know how to
do this?



7 Answers Found

Answer #1    Answered By: Joanna Dixon     Answered On: Apr 06

Can you expound on your question. I'm not sure what you are asking how
to do.

Answer #2    Answered By: Justine Barrera     Answered On: Apr 06

What I did is I followed this article:


I used this article before I make the webpart. I came
to a point that I
need to assign  value from a text box to a variable in
my script. How will I
be able to do it?

example (in C#.net):
private const string  EmbeddedScriptFormat =
"<script language=\"javascript\">" +
"\n function SaveName(){" +
"var getName=null;" +
"getName=txtGetName;" +
"}" +

txtGetName here is a textbox  control I add in my
webpart in the
RenderWebPart() method:

and I am aiming to use value of txtGetName.text in
other javascipt
functions. Please help me about how will I get the
value of the textbox.

Answer #3    Answered By: Sharonda Mcfarland     Answered On: Apr 06

Use this… “getName=’” + txtGetName.ClientID + “’” + ......

Answer #4    Answered By: Cory Brooks     Answered On: Apr 06

Another alternative is to assign  an ID to the textbox  server control
using myTextBox.Attributes.Add("ID", "TextBox1"); where myTextBox is a
C# variable that references an instance of your textbox on the server.
Then you can reference the text box in JavaScript using the common

Answer #5    Answered By: Ruth George     Answered On: Apr 06

Try using HtmlInputHidden control. This control can be accessed from both C# as well as Javascript.

Using getElementById method get the server side control in javascript and assign  there the value.

This is a good article:

Answer #6    Answered By: Peter Peterson     Answered On: Apr 06

Chances are you can’t get the control with getElementById… especially if you put HtmlInputHidden runat=”server”. The reason is because .net will add some stuff in front of the ID in order to make the control unique throughout the page. When Todd put myTextBox.Attributes.Add(“ID”, “TextBox1”), the ID of the textbox  is added and not handled by .net framework (I think), that’s why javascript can find the control at client side…

A general rule of thumb, if you assign  the ID in server side, and you want to access the control at client side, use ClientID… the framework will give you the correct value…

Answer #7    Answered By: Kalyan Pujari     Answered On: Apr 06

If generating JavaScript on the fly, I would agree with you Kit Kai.
However, if the JavaScript is in a static file linked to by the
framework, generating the element as a server control with an ID
attribute and then using getElementById on the client side to retrieve
the element is my general rule of thumb.

Didn't find what you were looking for? Find more on Get Textbox values Or get search suggestion and latest updates.