23

I want to fire a server-side ASP.NET button click event in JavaScript. I checked the page source and the button's onclick in client side is:

WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$LoginInfo1$btnliOK", "", true, "", "", false, false));

But I have to replace ctl00$LoginInfo1$btnliOK with something like <%= btnliOK.ClientName %>. Is there a way to do that?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
nima
  • 6,566
  • 4
  • 45
  • 57

1 Answers1

43

You can get it using the Control.UniqueID Property

btnliOK.UniqueID

UniqueID gives the on page rendered name
ClientID gives the on page rendered id
ID give's the id that you can use on code behind

Aristos
  • 66,005
  • 16
  • 114
  • 150
  • 5
    Just wanted to say thank you for this - this solved about six hours of frustration with the jQuery validation plugin! – scubbo Aug 08 '12 at 08:20
  • 2
    Thank you so much, I have been doing '.ClientID.Replace("_", "$")' for ages. Which was terrible is anything was named with a _ inside. – Malcor May 16 '14 at 14:14