Hi, Using the following code, I'm trying to add a client-side confirmation dialog before allowing a LinkButton to postback the form: MyLinkButton.Attributes.Add("href", "javascript:if (confirm('Are you sure?')) " + this.GetPostBackEventReference(MyLinkButton));
This actually achieves the desired behaviour, but there's one problem: checking the HTML output by the page, the LinkButton is actually emitting TWO href attributes - the one it would normally do, plus the one I added with my Attributes.Add statement. When
I click on the hyperlink, the code contained within MY href attribute is being called and I am getting the confirmation dialog like I want. But I'm really not comfortable with allowing that other href attribute to be emitted and I'd like to suppress it. Is
there any easy way of doing this that doesn't involve subclassing the LinkButton or something? Many thanks for any help you can give me, Dave
That's just what I needed - works great! My javascript's a bit light and I didn't know that returning false would cancel the action of the hyperlink. It works for the submit-type button control too, so its a perfect solution for me. Thanks very much!
davidgibb
Member
10 Points
2 Posts
Overriding the href attribute output by a LinkButton
Aug 05, 2003 05:57 AM|LINK
Tryster
Member
325 Points
63 Posts
Re: Overriding the href attribute output by a LinkButton
Aug 05, 2003 11:45 AM|LINK
MyLinkButton.Attributes.Add("onclick", "javascript:if (!confirm('Are you sure?')) return false")davidgibb
Member
10 Points
2 Posts
Re: Overriding the href attribute output by a LinkButton
Aug 05, 2003 10:40 PM|LINK