Click here to Skip to main content
14,111,188 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
Hi guys,

i want to use onclick event with hyperlink in asp.net.

my code:

1. <asp:HyperLink ID="hlpwd" runat="server" onclick="onclick_pwd();" NavigateUrl='#'>Forgot Password

2.
protected void onclick_pwd(object sender, EventArgs e)
{
if(pwdrecovery.Visible == true)
pwdrecovery.Visible = true;
else
pwdrecovery.Visible = false;
}


PLEASE SUGGEST ME HOW TO USE THIS EVENT WITH HYPERLINK.
Posted
Comments
Prince Tegaton 20-Sep-13 9:52am
   
Hyperlink does not have serverside events. Instrad use a LinkButton
JoCodes 20-Sep-13 14:41pm
   
what you want to achieve in the on click event?
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

You should try

<asp:hyperlink id="hlpwd" runat="server" xmlns:asp="#unknown">click="onclick_pwd();" NavigateUrl='#'>Forgot Password</asp:hyperlink>


I think your event code is not correct

Quote:
protected void onclick_pwd(object sender, EventArgs e)
{
if(pwdrecovery.Visible == true)
pwdrecovery.Visible = true;
else
pwdrecovery.Visible = false;
}


if pswrecovery is visible it will be forever visible, I think you wants to do that :

protected void onclick_pwd(object sender, EventArgs e)
{
if(pwdrecovery.Visible == true)
pwdrecovery.Visible = false;
else
pwdrecovery.Visible = true;
}
   
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

I used linkedbutton..
n
i edited my code
as
<asp:linkbutton id="lbnpwd" runat="server" onclick="LinkButton1_Click" xmlns:asp="#unknown">Forgot Password</asp:linkbutton>

protected void onclick_pwd()
{
    if (pwdrecovery.Visible == true)
    {
        pwdrecovery.Visible = false;
    }
    else
    {
        pwdrecovery.Visible = true;
        newuser.Visible = false;
    }
}

protected void LinkButton1_Click(object sender, EventArgs e)
  {
      onclick_pwd();
  }
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web02 | 2.8.190518.1 | Last Updated 20 Sep 2013
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100