Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 16th, 2006, 05:16 AM
Authorized User
 
Join Date: Aug 2006
Location: , , .
Posts: 39
Thanks: 1
Thanked 0 Times in 0 Posts
Default Link button not working !!! eh....

Hello,

I've two LinkButtons on form. First link button updates time, second calls javascript function. Untill I click second, first works properly. As I click second, after then first does not work at all.

My code is as follows:

<%@ Page Language="C#" %>

<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LinkButton1.Text = "Time: " + System.DateTime.Now.ToLongTimeString();
            LinkButton2.PostBackUrl = "javascript:SayHello();";
        }
    }

    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        LinkButton1.Text = "Time: " + System.DateTime.Now.ToLongTimeString();
    }
</script>

<html>
<head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript">
        function SayHello()
        {
            alert("Hello");
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click"></asp:LinkButton>
        <asp:LinkButton ID="LinkButton2" runat="server">Say Hello</asp:LinkButton></div>
    </form>
</body>
</html>

Any idea? Thanks in advance.


  #2 (permalink)  
Old November 24th, 2006, 08:30 AM
Authorized User
 
Join Date: May 2006
Location: New Delhi, Delhi, India.
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try to call javascript in the click event of link button

-------------------
rajkumar sharma
http://www.apnasaathi.blogspot.com
  #3 (permalink)  
Old November 28th, 2006, 11:45 PM
Friend of Wrox
 
Join Date: Feb 2006
Location: , , USA.
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I don't think you should set the PostBackUrl property on that linkbutton. I think you should just use the onclick property to call your javascript function. PostBackUrl probably screws with the whole web form because it's intended purpose is to post the whole form back to another URL.

I only modified one line:

Code:
<%@ Page Language="C#" %>

<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LinkButton1.Text = "Time: " + System.DateTime.Now.ToLongTimeString();
            //LinkButton2.PostBackUrl = "javascript:SayHello();";            
            LinkButton2.Attributes.Add("onclick", "SayHello()");
        }
    }

    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        LinkButton1.Text = "Time: " + System.DateTime.Now.ToLongTimeString();
    }
</script>

<html>
<head id="Head1" runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript">
        function SayHello()
        {
            alert("Hello");
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click"></asp:LinkButton>
        <asp:LinkButton ID="LinkButton2" runat="server">Say Hello</asp:LinkButton>
    </div>
    </form>
</body>
</html>
Neil Timmerman
Programmer
Veris Consulting
  #4 (permalink)  
Old November 29th, 2006, 12:21 PM
Authorized User
 
Join Date: Sep 2006
Location: , , India.
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

HI , use "onclientclick" method of the control
to call ur clientside javascript function.

  #5 (permalink)  
Old December 14th, 2006, 12:43 AM
Authorized User
 
Join Date: Aug 2006
Location: , , .
Posts: 39
Thanks: 1
Thanked 0 Times in 0 Posts
Default

hi

Thanks Neil Timmerman and SriRamaKrishna
your suggestions really helped me out to get issue resolved.


  #6 (permalink)  
Old March 27th, 2008, 03:44 AM
Registered User
 
Join Date: Feb 2008
Location: http://www.GlobalGuideLine.com, , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi nitinp
i need some help; i have two pages first page's links are working and second page's asp link is not working i mean event of this link is not firing even the page is firing isPostBack but its own event is not firing. Help me if you can
Thanks.



webmaster http://www.GlobalGuideLine.com
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
anchor link not working in IE6 sbkumar CSS Cascading Style Sheets 2 July 29th, 2008 11:27 AM
Link Button deontae45 ASP.NET 1.0 and 1.1 Basics 2 June 23rd, 2007 04:46 PM
Link Button sohrabus ASP.NET 2.0 Professional 1 November 14th, 2006 08:33 AM
Link Button sohrabus ASP.NET 1.0 and 1.1 Professional 3 October 27th, 2006 07:08 AM



All times are GMT -4. The time now is 08:33 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.