views:

51

answers:

3

I have a button when i click it, some text from a textbox is got and written inside a p tag via javascript. I have another button that cause page postback. But after postback, contents which added by javascript are disappearing.

Is there a way to solve this problem ?

+2  A: 

Either use ajax to postback part of the page excluding the part you change with javasciprt or store the changes in a formfield so that they can be remade after postback.

Clientside javascript changes are not visible to the server and will disapear efter postback since the page is renderd from start again.

David Mårtensson
Can you a bit explain this technic please: "store the changes in a formfield so that they can be remade after postback."
mavera
Depends much on you specific solution but the important thing to remember is that any thing done client side that is not in a form field is lost on postback. If the button had been a postback button the server would have stored the information you wrote to the p tag in the page viewstate, but viewstate is only accesable from the server, not client.
David Mårtensson
A: 

If you're using C# and ASP .NET, try using server-side controls and functions instead of javascript. These preserve their state during postback.

Or do you really must use javascript?

naruu
A: 

You can use ajax Update panel to partial post back the page on buton click

Nitesh Katare