Handling OnClick and GetPostBackEventReference

G

Guest

I am writing a control and want to handle an OnClick event on the client-side
before then conforming to the postback mechanism. I have got the server-side
events working for my OnClick event by adding to the rendered element's
OnClick handler using GetPostBackEventReference. How can I provide a
client-side onclick handler and then to use the aspnet form submit method
such that I can also subscribe to the server-side events too?
 
B

bruce barker

define a property (say OnClientClick) then if set add it to the onclick
attribute before the get:

writer.AddAttributes("onclick",
OnClientClick + GetPostBackEventReference(options);


-- bruce (sqlwork.com)
 
G

Guest

Bruce,

Thanks for the reply. My question wasn't really worded very well and of
course your suggested code is the simple part which I have done. My question
was really about the way in which GetPostBackEventReference was working. I
had set-up my client-side handler using javascript passing a var from the
onclick call as you suggested. My problem was with the output of the asp.net
method GetPostBackEventReference of the ClientScriptManger class as below;

__doPostBack('ctl00$BDTabMenu1','Menu1');

Because, I had passed a var to my function i.e. funtion fname(x) {....}

I was trying to find a way to output a varname in the argument part of the
GetPostBackEventReference but couldn't get round the way it was rendering it
in a string! My fix was to iterate over my data source and output script for
a switch statement, then allowing me to use the explicit
__doPostBack('ctl00$BDTabMenu1','Menu1'); calls in each case, as below;

switch(x)
{
case 'Menu1' :
{
aElement.value=0;
__doPostBack('ctl00$BDTabMenu1','Menu1');
break;
}
case 'Menu2' :
{
aElement.value=1;
__doPostBack('ctl00$BDTabMenu1','Menu2');
break;
}
}

anyway, I now have a different gripe with master and content pages and
events within my custom control, which I have posted to verious other threads!

Thanks again!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top