Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2007

Tip: Looking for answers? Try searching our database.

HyperLink, JavaScript and PostBack

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
andrew.douglas11@gmail.com - 29 Oct 2007 19:55 GMT
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>
Göran Andersson - 29 Oct 2007 20:41 GMT
> 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.

Signature

Göran Andersson
_____
http://www.guffa.com


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.