[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 325
  • Last Modified:

Getting the text from TextBox after JavaScript insertion

Hi!

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

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

Open in new window


In ASPX:
    <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;
            }
    </script>

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!
0
calypsoworld
Asked:
calypsoworld
  • 4
  • 3
  • 3
  • +1
2 Solutions
 
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
0
 
calypsoworldAuthor Commented:
>robbhill

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!
0
 
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.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
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 it...so without doing a postback..you 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:)


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

Open in new window

0
 
puru1981Commented:
just remove the readonly attribute from the textbox it will work like a charm
0
 
Anil GolamariCommented:
0
 
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!
0
 
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){
document.getElementById(e).innerHTML+=val;
}
</script>
<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

0
 
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">
            <ContentTemplate>
                  <asp:TextBox ID="txtbox1" runat="server" AutoPostBack="False"></asp:TextBox>                
         
              </ContentTemplate>
        </asp:UpdatePanel>

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.

     
0
 
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 panel...it just needs to be dynamically created ont the fly each time the other source sends the data.
0
 
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.

Regards.
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 4
  • 3
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now