Loading ...

Link Button OnClientClick() & OnClick() event

Who is online?  0 guests and 0 members
home  »  forums   »  asp.net topics   »  client side web development   » Link Button OnClientClick() & OnClick() event

Link Button OnClientClick() & OnClick() event

Posts under the topic: Link Button OnClientClick() & OnClick() event

Posted: 7/15/2011

Lurker 245  points  Lurker
  • Joined on: 4/15/2011
  • Posts: 44

I have 2 link buttons with OnClientClick() & OnCommand() events

OnClientClick() i am opening a  samll window

& OnCommand() event I want to know on  which Linkbutton user has click

protected void  LinkButton_Command(object sender, CommandEventArgs e)

        {

             if (e.CommandName == "Friend")

                {

                    Session["type"] = "f";

                }

                if (e.CommandName == "Privatemessage")

                {

                    Session["type"] = "p";

                }

           

        }

 

but my  LinkButton_Command event is not firing

 

 


Posted: 7/15/2011

Guru 16773  points  Guru
  • Joined on: 4/19/2009
  • Posts: 490

Please show the sufficient code to reproduce your issue.


Posted: 7/18/2011

Lurker 245  points  Lurker
  • Joined on: 4/15/2011
  • Posts: 44

Ok fine

my java script function is:-

script type="text/javascript">

                    

        function openRadWin()

           {

               radopen("friendrequest.aspx?","RadWindow1");

           }

                                                                             

</script>

& on .aspx page i have 2 link buttons like this

<li>

    <asp:LinkButton ID="LinkButton1" runat="server"  OnClientClick="openRadWin(); return false;"oncommand="LinkButton_Command" CommandName="Friend"CausesValidation="False" >Add As a Friend

</asp:LinkButton>

 

</li>

 

<li >

   <asp:LinkButton ID="LinkButton2"  oncommand="LinkButton_Command"

    OnClientClick="openRadWin(); return false;"  runat="server"

    CommandName="Privatemessage" CausesValidation="False">

    Send Message</asp:LinkButton>

</li>

 

linkbutton commcnd event is

 

protected void  LinkButton_Command(object sender, CommandEventArgs e)

    {

          if (e.CommandName == "Friend")

              {

                    Session["type"] = "f";

              }

 

          if (e.CommandName == "Privatemessage")

              {

                    Session["type"] = "p";

              }

           

     }

 

but my LinkButton_Command event is not firing

 

 


Posted: 7/18/2011

Starter 1414  points  Starter
  • Joined on: 12/1/2008
  • Posts: 66

Hello,

There is nothing wrong with your code. I copied your code and ran it. The Command  event is getting fired.

One of my collegue also faced the same issue.  He just copied his code into the new page and it started working.

I would suggest you to do the same. Just copy and paste it in a new web form and then try to run it.

 

Hope this helps.

 

Thanks & Regards,

Sumit Arora

           

     


Posted: 7/18/2011

Lurker 245  points  Lurker
  • Joined on: 4/15/2011
  • Posts: 44

Hi Sumit,

Thanks,

I have coppied the code to another page & ran it but it still does not works


Posted: 7/18/2011

Guru 16773  points  Guru
  • Joined on: 4/19/2009
  • Posts: 490

pallavi karpe said:

but my LinkButton_Command event is not firing


It will not fire because you yourself are stopping it. You have written "return false;" :
pallavi karpe said:

OnClientClick="openRadWin(); return false;"


So why would the server side code will fire ? since you are telling the page to stop the default action on click of link button, which is a postpack.


Posted: 7/19/2011

Lurker 245  points  Lurker
  • Joined on: 4/15/2011
  • Posts: 44

yes raghav you r right,

but when i say return true then rad window immegiately get closed

so wht to do to keep it open unless user close it


Posted: 7/19/2011

Guru 16773  points  Guru
  • Joined on: 4/19/2009
  • Posts: 490

You must be having some button on your RAD modal. Write your logic on click of that button instead of command of link button.


Posted: 8/8/2011

Lurker 125  points  Lurker
  • Joined on: 5/24/2011
  • Posts: 9

Remove  return false; from OnclientClick event.


Page 1 of 1 (9 items)