Getting the text from TextBox after JavaScript insertion


I have an Applet that send strings to a webpage through LiveConnect.

In Java:
JSObject window = JSObject.getWindow(this);"writeStatusOnPage", new Object[]{text});

Open in new window

    <script type="text/javascript" language="javascript">
            function writeStatusOnPage(texto) {
                var address = texto;
                var prevValue = document.getElementById("ctl00_contentplaceholderbody_TextBox2").value;
                document.getElementById("ctl00_contentplaceholderbody_TextBox2").value = prevValue + "\n" + address;

Open in new window

The applet sends the string very well and it appears in page.
The problem is that I'm trying to read the TextBox2.Text from C# codebehind and it's returning "", even it's already filled with the string sent from Java (and inserted with Javascript with .value property).

What I'm doing wrong?

Thanks in advance!
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Robb HillSenior .Net DeveloperCommented:
You are trying to put a client side value on a server side call...u may need to play the value from jscript in a hidden field..then capture the value on your postback
calypsoworldAuthor Commented:

Thank you for reply!

The textbox control is server-side.
<asp:TextBox ID="txtsimid" runat="server" ReadOnly="true" CssClass="textboxes"></asp:TextBox>

I can't do a postback on this page... Maybe with AJAX... I don't know. But the page shouldn't be reloaded.

Thank you!
Anil GolamariCommented:
If you want avoid the whole page to be reloaded then you can use Update panel so that only the control will be loaded. Because you said it is live content and it may update regularly so you can just add that textbox to update panel and then load the textbox will the value from javascript.
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Robb HillSenior .Net DeveloperCommented:
Well if you want all this to happen on the initial load then the textbox has to be there before you pass the value to without doing a would have to write a script for creating the textbox with javascript and pass the value then.

Always take note of the Page Life Cycle process.  There may be other ways to do this with jquery and ajax..but this works too:)

document.getElementById("somediv").innerHTML="<input type=\"text\"...blah blah...></input>";

Open in new window

just remove the readonly attribute from the textbox it will work like a charm
Anil GolamariCommented:
calypsoworldAuthor Commented:
When the user clicks on RUN button on applet, the applet sends a string to a textbox on webpage.
This value will not change, it's sent from Java only once.

> robbhill
Sorry, I didn't understand the solution that creates a input box.

> lucky85
Your suggestion is to put the textbox inside an UpdatePanel, right? And after that, what should I do?
Sorry, can you be more specific?

Thanks a lot, everybody!
Robb HillSenior .Net DeveloperCommented:
ok...simple hello goodbye example...just pass your java value in where I am putting text.
<script type="text/javascript">
function insertText(val,e){
<textarea id="textIns"></textarea><br />
<a href="javascript:insertText('Hello ','textIns');" onClick="void(0)">Insert 'Hello'</a><br /><a href="javascript:insertText('GoodBye ','textIns');" onClick="void(0)">Insert 'GoodBye'</a>

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Anil GolamariCommented:
Step1: As you don't want to reload the whole page everytime there is change in the textbox, I have asked to place the textbox in a update panel something  like

<asp:UpdatePanel ID="upnlDodajFirma" runat="server" UpdateMode="Conditional">
                  <asp:TextBox ID="txtbox1" runat="server" AutoPostBack="False"></asp:TextBox>                

Step2: You are pulling value using javascript from someother source right, now append that data to the textbox something like this

function clickevent()  
var txtbox1 = document.getElementById("txt1");    

// code behind

txtbox1.Attributes.Add("onclick", "javascript:clickevent();");

Good Luck.

Robb HillSenior .Net DeveloperCommented:
If the value is never changed on a postback..there is no need to wire it with Ajax or an update just needs to be dynamically created ont the fly each time the other source sends the data.
calypsoworldAuthor Commented:
There is no problem with this operation. I was calling the column name on DB with a wrong name...
Thank you for all the replies anyway!

Now that problem is solved, I have another issue with UpdatePanels and Timer, but I'll put it on another question.

Once again, thank you very much and I'm sorry for the mistake.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.