.NETGURU
LinkButton Bug
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngescalate' list.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

Brian Bilbro (VIP)
Posting this to escalate in hopes that the right people see it:

I've noticed that the link button uses javascript to do postbacks but there
is one problem with this. form.submit() doesn't call the form onSubmit code
(if any is defined)....I have a user control that requires some processing
when the form is submitted. But if the user control is used in page that
uses linkbuttons (instead of normal submit buttons) then my onSubmit code
doesn't fire (the user control registers the onSubmit code via
Page.RegisterOnSubmitStatement).

http://www.aspalliance.com/bbilbro/test/onsubmit.aspx
I created a simple page to showing this problem:

'---------------------------------------------------onSubmit.aspx-----------
-----------------------------------------------------------------------

<%@ Page language="vb" runat="server" Trace="False"%>
<%@ Register TagPrefix="NeedOnSubmit" TagName="MyControl"
Src="ControlOnSubmit.ascx" %>
<script language="VB" runat="server">
Sub LinkButton_Click(sender As Object, e As EventArgs)
Label1.Text = "You clicked the link button"
End Sub
</script>
<HTML>
<HEAD>
<TITLE>test</TITLE>
</HEAD>
<BODY>

<FORM RUNAT="Server">

<NeedOnSubmit:MyControl id="ListGrid" runat="server"/>

<asp:LinkButton id="LinkButton1"
Text="Click Me"
Font-Name="Verdana"
Font-Size="14pt"
OnClick="LinkButton_Click"
runat="server"/>

<p>

<asp:Label id=Label1 runat=server />
</FORM>
</BODY>
</HTML>

'---------------------------------------------------ControlOnSubmit.ascx----
----------------------------------------------------------------------------
--

<script language="VB" runat="server">
Sub Page_Load(Src As Object, E As EventArgs)
Page.RegisterOnSubmitStatement("DualSelect_onSubmit","alert('I am a user
control that need to do some processing on a form submit! Please call
me!');")
End Sub
</script>
<center>
<table border=1>
<tr><td>
I am a user control that needs to do some processing on the form
submit...But from some reason hyperlink that do a form.submit() doesn't call
my onSubmit event. :(
</td></tr>
</table>
</center>

I was thinking if Page.RegisterOnSubmitStatement would make the code
available so that the _doPostBack function code call it then everything
would be great! For example:
<script language="javascript">
<!--
function __doPostBack(eventTarget, eventArgument) {
var theform = document.ctrl0;
theform.__EVENTTARGET.value = eventTarget;
theform.__EVENTARGUMENT.value = eventArgument;
if(!(__doSubmit()==false)) theform.submit();
}

function __doSubmit()
{
// this is where any code that is placed
// in Page.RegisterOnSubmitStatement will also
// be put
return confirm('continue?');
}

// -->
</script>

which would over come this

shows the kind of resulting client code:
with some code the return a boolean
http://www.aspalliance.com/bbilbro/test/onsubmit.htm
with some code the doesn't return a boolean
http://www.aspalliance.com/bbilbro/test/onsubmit2.htm

Note: I do
if(!(__doSubmit()==false))
instead of
if(__doSubmit()==true)

in case the onSubmit code doesn't return everything (and we get an
'undefined')

Thanks,
Brian
Reply to this message...
 
    
marshall_brooke@gabrobins.co.uk

Brian,

This is an IE issue. If you submit the form through code form.submit() the
onsubmit event will not fire. I've forgotton why or if there is indeed a
reason for this. Check out http://msdn.microsoft.com/library/default.asp
for more info.

hth

Marshall
The Information in this e-mail and in any attachments is confidential
and intended only for the addressee. If you are not the intended
recipient, any disclosure, copying or distribution of this e-mail or
any attachments is strictly prohibited. Please notify the sender
immediately by return e-mail and delete any message and
attachments.

We believe that this e-mail and any attachments are free from any virus
or other defects which may affect any computer system, but it remains
the responsibility of the recipient to ensure that it is virus free.
The GAB Robins group of companies accept no responsibility for any
loss or damage arising in any way from its use.

Reply to this message...
 
    
Brian Bilbro (VIP)
Netscape does the same thing. But either way.. I've presented a solution to
the problem and hope it gets integrated in some form (there are other
possible solutions).

Bottom line is, in it's current implementation, you can't reliably use
Page.RegisterOnSubmitStatement in your user or custom controls unless the
__doPostBack is enhanced to also execute that code.

--
Brian

----- Original Message -----
From: <Click here to reveal e-mail address>
To: "aspngescalate" <Click here to reveal e-mail address>
Sent: Thursday, November 15, 2001 3:34 AM
Subject: [aspngescalate] Re: LinkButton Bug

[Original message clipped]

Reply to this message...
 
 
System.EventArgs
System.Web.UI.Page
System.Web.UI.WebControls.LinkButton




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification