Search:
Namespaces
Discussions
.NET v1.1
Feedback
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
Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us
-
Terms of Use
-
Privacy Policy
-
www.dotnet247.com