0

i have a serverside textbox like this:

<asp:TextBox runat="server" id="testText" >hi this is a world!</asp:TextBox>

so i change this value in clienside with javascript like this

document.getElementById("<%=testText.ClientID%>").value="Hahaha"

when i read value it write like blow code in codebehind it print "hi this is a world!" value why?

 response.write(testText.text); // print "hi this is a world!"
3
  • did you disable the viewstate? Commented Dec 2, 2012 at 7:37
  • no viewstate is enabled and i used it in my code-behind several times Commented Dec 2, 2012 at 7:39
  • 1
    To read it you need to make post back - do you make post back ?. Also this lines is not the actually code that make the issue, they are just lines. Can you give us the part of the code on javascript that you change it, and in the code behind. This issue here can be solve by you , if you debug your code and see if its actually change, and how the value is not return back and you get again the initial. Commented Dec 2, 2012 at 7:43

3 Answers 3

1

When you are rendering the text through request and response, it takes the value from server so your request and response will show the value set on server. Javascript works only on client side and once the document is loaded,it is not dependent on request and response.

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

Comments

0

your question is not clarifying to me! but suppose you have also button to change the text, you can change it according to requirment

<asp:TextBox ID="testText" runat="server" ClientIDMode="Static">hi this is a world!</asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button"></asp:Button>

Add an event of javascritp on your Page_Load (i am adding onclick event to button for handling javascript function)

Button1.Attributes.Add("onclick", "javascript:clientsite()");

then i think you want change server site value from client site, so for this you have to replace the value

 function clientsite() {

    var servervalue = document.getElementById("testText").value;
    var replaceIt = servervalue.replace(servervalue, "hahaha");
    document.getElementById("testText").value = replaceIt;
}

Now when you click on button it will replace or change a value from server side to client side
may be this can be helpful to you

happy coding :D

Comments

0

I know, this question has been asked long ago, but still adding my answer as it might be helpful to someone.

Use following line of code :

response.write(Request.Form.Get(testText.UniqueID));

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.