problem about postback and javascript

P

Phil

Hi,

There is a label and a textbox.
There are two buttons: one HTML (buttonA), the other ASP.NET (ButtonB).
Clicking on buttonA starts a javascript function, starting on ButtonB
triggers nothing but of course generates a postback.

Now my problem.
When clicking on buttonA, the text of the textbox and of the label are
modified by javascript, as expected.
When after that clicking on ButtonB, the only thing that happens is a
postback, so the original text of the label is back, but not as expected,
the original text of the textbox: it's still "textboxtext modified by
javascript".
Why?

Thanks
Phil

<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" Width="250px" Text="text
of textbox"></asp:TextBox>
<asp:Label ID="Label1" runat="server" Text="text of
label"></asp:Label>
<input id="Button1" type="button" value="buttonA" onclick="client()"
/>
<asp:Button ID="Button2" runat="server" Text="ButtonB" />
</div>
</form>
</body>
<script type="text/javascript">
function client()
{
document.getElementById("TextBox1").value="textboxtext modified by
javascript"
document.getElementById("Label1").innerText="labeltekst modified by
javascript"
}
</script>
 
B

bruce barker

because textbox values are posted back. it doesn't matter if the user or
javascript changes the value.

a label is not a browser form element (input,select or textarea), so any
changes are not posted back.

-- bruce (sqlwork.com)
 
P

Phil

Thanks

bruce barker said:
because textbox values are posted back. it doesn't matter if the user or
javascript changes the value.

a label is not a browser form element (input,select or textarea), so any
changes are not posted back.

-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top