1

I add a GridView on page in UpdatePanel and put a Panel in one of cells and add LinkButton from code behind to this panel like below

Panel pnl = (Panel)GridView1.Rows[i].Cells[4].FindControl("pnlSteps");//pnlSteps is Panel's Id
LinkButton lnk = new LinkButton();
//...
pnl.Controls.Add(lnk);

when user click on each LinkButton I want to run a javascript's function,how can i do it?

2 Answers 2

1

You can use like this

Panel pnl = (Panel)GridView1.Rows[i].Cells[4].FindControl("pnlSteps");
LinkButton lnk = new LinkButton();
lnk.attributes.Add("onclick", "YourFunction();");
pnl.Controls.Add(lnk);

And in java-script create a function as follows

<script type="text/javascript">
  function YourFunction()
  {
        alert("function called");
        return false;//don't forgot this
  }
</script>
Sign up to request clarification or add additional context in comments.

1 Comment

You are welcome. Don't forgot to mark the answer if it helped you.
1

Raise OnClick Event on the function like this.

lnk.attributes.Add("onclick", "function()");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.