HyperLink, JavaScript and PostBack

A

andrew.douglas11

Hello - I'm trying to dynamically change an asp:HyperLink's text
through JavaScript, and finding that the new value that's set in
JavaScript doesn't get posted back. I've tried to explicitly set
EnableViewState to "True", but that doesn't help. Is there a better
way to do this and still update the text through client-side code?
The entire code appears below (no 'code behind' code).

Thanks!

Andy



<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Test.aspx.vb"
Inherits="Test" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script>
function updateLink() {
document.getElementById("HyperLink1").innerText = "POSTBACK
PLEASE";
document.getElementById("DropDownList1").value = "2";
alert("pause to verify new values...");
//go ahead and post back
return true;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:HyperLink ID="HyperLink1" runat="server">HyperLink</
asp:HyperLink>
<br />
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Value="1"></asp:ListItem>
<asp:ListItem Value="2"></asp:ListItem>
</asp:DropDownList>
<br />
<asp:Button ID="Button1" runat="server" OnClientClick="return
updateLink()" Text="Button" />
</div>
</form>
</body>
</html>
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Hello - I'm trying to dynamically change an asp:HyperLink's text
through JavaScript, and finding that the new value that's set in
JavaScript doesn't get posted back. I've tried to explicitly set
EnableViewState to "True", but that doesn't help. Is there a better
way to do this and still update the text through client-side code?

It's impossible to change the server controls text through Javascript.
The server control only exists on the server while the page is created,
the only thing that exists in the browser is the elements that the
browser has created from the html code that the server control has rendered.

The text of the link is not posted back to the server. The only things
that are posted back are the values in the form fields. If you want
anything posted to the server you have to put it in a form field.

The innerText property only exists in Internet Explorer. Use innerHTML
instead.
 

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

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,697
Latest member
AugustNabo

Latest Threads

Top