Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 16th, 2006, 05:16 AM
Authorized User
 
Join Date: Aug 2006
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.


 
Old November 24th, 2006, 08:30 AM
Authorized User
 
Join Date: May 2006
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
 
Old November 28th, 2006, 11:45 PM
Friend of Wrox
 
Join Date: Feb 2006
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
 
Old November 29th, 2006, 12:21 PM
Authorized User
 
Join Date: Sep 2006
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

 
Old December 14th, 2006, 12:43 AM
Authorized User
 
Join Date: Aug 2006
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.


 
Old March 27th, 2008, 03:44 AM
Registered User
 
Join Date: Feb 2008
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





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





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