Apply Jquery Function in click event of Link button (in code behind)

11,511

Solution 1

You can bind the javascript function to linkbutton and it will show popup on click

<asp:LinkButton id="lnk" runat="server" OnClientClick="ShowPopUp();">

if you have linkbutton as id you can use jquery to bind script

$('#linkbutton').click(ShowPopUp);

if you have linkbutton as class you can use jquery to bind script

$('.linkbutton').click(ShowPopUp);  


function ShowPopUp(){
  TINY.box.show({
  iframe:'User_News.aspx',
  boxid:'frameless',
  width:250,
  height:250,
  fixed:false,
  maskid:'bluemask',
  maskopacity:40,
  closejs:function(){closeJS()}
  });
}

Solution 2

include jquery library - https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js

Considering Linkbutton as classname add this in Script tag -

$(function(){
  $('.Linkbutton').on('click', function(){
    $('#frameless').show();
  });
});
Share:
11,511
Mitesh Machhi
Author by

Mitesh Machhi

Updated on June 05, 2022

Comments

  • Mitesh Machhi
    Mitesh Machhi almost 2 years

    this is another question that I want to know that how to apply any jQuery function on onclick() event of Linkbutton.

    I have a one Linkbutton and I want to set below jQuery function when linkbutton is clicked.

    <önclick="TINY.box.show({
        iframe:'User_News.aspx',
        boxid:'frameless',
        width:250,
        height:250,
        fixed:false,
        maskid:'bluemask',
        maskopacity:40,
        closejs:function(){closeJS()}
    })"
    style="color: #0000FF; font-size: medium; height: 28px;"
    id="l1" 
    runat="server">
    

    This function gives me a popup message. So how to get this popup when linkbutton is clicked?

    • Roman
      Roman almost 12 years
      That doesn't even look like a valid tag, are you sure your code does anything?
    • Mitesh Machhi
      Mitesh Machhi almost 12 years
      i have same like <li onclick="TINY.box.show({iframe:'User_News.aspx',boxid:'frame‌​less',width:250,heig‌​ht:250,fixed:false,m‌​askid:'bluemask',mas‌​kopacity:40,closejs:‌​function(){closeJS()‌​}})" style="color: #0000FF; font-size: medium; height: 28px;" id="l1" runat="server">View Message </li>
    • Mitesh Machhi
      Mitesh Machhi almost 12 years
      yes. i am using the .net with c#.
  • Adil
    Adil almost 12 years
    On which statement you get error and what is the error? Are you using asp.net ?
  • Mitesh Machhi
    Mitesh Machhi almost 12 years
    when i am writing this code in Script Function. and javascript function not work.
  • Adil
    Adil almost 12 years
    On which statement you get error and what is the error? Are you using asp.net ?
  • Mitesh Machhi
    Mitesh Machhi almost 12 years
    yes sir. i am using c#.and when i call that function it does not work.
  • Adil
    Adil almost 12 years
    c# does not mean that you are using asp.net. I want to know if you are using asp.net ?
  • Mitesh Machhi
    Mitesh Machhi almost 12 years
    yes sir. i am using the asp.net. and for more info. to you that when i click on link button the code which you have suggest to me to write inside the function in not work. please tell me and it not call that jquery function.
  • Adil
    Adil almost 12 years
    Do you know how to debug javascript? and what browser you have?
  • Mitesh Machhi
    Mitesh Machhi almost 12 years
    i am use Alert("xxxx") and i use Google Chrome.
  • Adil
    Adil almost 12 years
    This is my answer to show how to debug please debug and tell me exact error you getting stackoverflow.com/questions/10573819/…
  • Mitesh Machhi
    Mitesh Machhi almost 12 years
    now, some changes i made and it looks like o.k. but also one problem that when click on linkbutton it display pop up sometime only for few seconds then after it goes back. it comes sometime only not for all time when i click on linkbutton.
  • Adil
    Adil almost 12 years
    You need to close popup to show it again because sometime it is minimized. Also try return fasle; from ShowPopUp() function and tell me what happens
  • Mitesh Machhi
    Mitesh Machhi almost 12 years
    solved it brother and Thanks for Your suggestion and Chat with me to solve my problem.