Click here to Skip to main content
11,582,584 members (71,891 online)
Rate this: bad
good
Please Sign up or sign in to vote.
Hi,

I have UltraWebGrid which I create dynamically, using DataBind and a helper class.
In the InitializeRow event, I generate ImageButtons in one of the columns.

Clearly, since it's ImageButton I need it to call a function.
normally, I set the function using Attribute.Add, and call a javascript:

img.Attributes.Add("onclick", "DoSomething();");

But Some of the functions should be server side (since it supposed to call the business logic layer).
I know that if I have a code-behind OnClick function and I would like to add client-side command I could do something like that:

this.btnSomething.Attributes.Add("onclick", "JavascriptFunction();" + this.Page.ClientScript.GetPostBackEventReference(btnSomething, "").ToString());

But it calls the code-behind function which is already attached to the buttons and just adds the Javascript function.

How can I call a code behind function which is not connected in any way to the imagebutton dynamically? (I currently use Attribute.Add, but if there's some other way to do that - I'd love to know)

Thanks.
Posted 13-Aug-12 21:10pm
DanaH85575

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try use ".OnClientClick" instead of ".Attributes.Add"
ImageButton1.OnClientClick = "javascript:alert('Some JS Stuffs Here');";
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 335
1 Sergey Alexandrovich Kryukov 220
2 Andy Lanng 124
3 virusstorm 109
4 Kornfeld Eliyahu Peter 90
0 OriginalGriff 1,358
1 Sergey Alexandrovich Kryukov 970
2 Abhinav S 671
3 F-ES Sitecore 505
4 Suvendu Shekhar Giri 448


Advertise | Privacy | Mobile
Web03 | 2.8.150603.1 | Last Updated 15 Aug 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100