Overwriting the "href='javascript:__doPostBack........" in a LinkButton

J

Jeffrey

I'm building a custom LinkButton control that will confirm a deletion
before processing it.

I've tried a few different things, some partially successful, and I
did find someone who had a script that does this (though I didn't like
the implementation so I'm still trying).

I'm wondering if there is any way to inherit the
System.Web.UI.WebControls.LinkButton class, and then overwrite how it
renders the "href='javascript:__doPostBack('....','')" attribute.

I figure that I could register a custom javascript with the page, and
then have the href point to my script, which then runs instead.

I can't figure out how to do this. Is it possible? If so, how?

Thanks,
Jeffrey
 
J

JohnnyV

Hi,

Register your client script function in the OnPreRender event of
your control. In the Render event, get the html that is to be rendered to
the client, from the HtmlTextWriter object that is passed to the method,
modify this html so that the href points to your function and then render
the modified html to the client.

Regards
 
A

Anthony Williams

Jeffrey said:
I'm building a custom LinkButton control that will confirm a deletion
before processing it.

I've tried a few different things, some partially successful, and I
did find someone who had a script that does this (though I didn't like
the implementation so I'm still trying).

LinkButton.Attributes.Add("onclick", "return confirm('Are you sure?');")
 

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,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top