0

In my webform I created button from my code behind:

Button btnShowCase = new Button();
btnShowCase.ID = "btnShowCase_" + ticketNumber;
btnShowCase.CssClass = "BtnShowCase";
btnShowCase.Text = "Display";
btnShowCase.OnClientClick = "ShowCase";

On client click I want to execute function

protected void ShowCase(object sender, EventArgs e)
{
Do something
}

OnClientClick do not call ShowCase. What I am doing wrong?

2 Answers 2

5

Instead of

btnShowCase.OnClientClick = "ShowCase";

Try

btnShowCase.OnClick += ShowCase;

ClientClick invokes Javascript that runs within the browser; the string argument is the name of a Javascript function. Click causes a postback and invokes a server-side method; the argument is a method that matches the delegate for the event type.

Sign up to request clarification or add additional context in comments.

2 Comments

When tried OnClick, I got error: button.onclick inaccesible duo to its protection level. I tried this: 'btnShowCase.Click += new EventHandler(ShowCase);'
Unfortunately never arrived to Showcase function. in Crome dev tools on client it is appear like this: href="javascript:__doPostBack('btnShowCase_CAS-17125','')"
-1

OnClientClick is an event handler, and should be set like this:

btnShowCase.OnClientClick += "ShowCase";

instead of

btnShowCase.OnClientClick = "ShowCase";

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.