Last active
December 14, 2015 13:18
-
-
Save rousso/5092436 to your computer and use it in GitHub Desktop.
The code in this gist supports this blog article: http://rousso.blogspot.com/2006/12/multiple-calls-to-registeronsubmitstate.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
<!-- | |
function WebForm_OnSubmit() { | |
alert('This is registered by OnSubmitControlA'); | |
alert('This is registered by OnSubmitControlB'); | |
if (typeof(ValidatorOnSubmit) == "function" && ValidatorOnSubmit() == false) | |
return false; | |
return true; | |
} | |
// --> | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
<!-- | |
function WebForm_OnSubmit() { | |
alert('This is registered by OnSubmitControlA'); | |
if (typeof(ValidatorOnSubmit) == "function" && ValidatorOnSubmit() == false) | |
return false; | |
alert('This is registered by OnSubmitControlB'); | |
return true; | |
} | |
// --> | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="OnSubmitControlA.ascx.cs" Inherits="OnSubmitControlA" %> | |
<asp:TextBox ID="TextBox1" runat="server" /> | |
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1" ErrorMessage="RequiredFieldValidator" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public partial class OnSubmitControlA : System.Web.UI.UserControl | |
{ | |
protected override void OnPreRender(EventArgs e) | |
{ | |
Page.ClientScript.RegisterOnSubmitStatement(this.GetType(), "DoingSomething", "alert('This alert is registered by OnSubmitControlA');"); | |
base.OnPreRender(e); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public partial class OnSubmitControlA : System.Web.UI.UserControl | |
{ | |
protected override void OnLoad(EventArgs e) | |
{ | |
base.OnLoad(e); | |
Page.ClientScript.RegisterOnSubmitStatement(this.GetType(), "DoingSomething", "alert('This alert is registered by OnSubmitControlA');"); | |
} | |
protected override void OnPreRender(EventArgs e) | |
{ | |
// Let's comment this out | |
// Page.ClientScript.RegisterOnSubmitStatement(this.GetType(), "DoingSomething", "alert('This alert is registered by OnSubmitControlA');"); | |
base.OnPreRender(e); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="OnSubmitControlB.ascx.cs" Inherits="OnSubmitControlB" %> | |
<asp:TextBox ID="TextBox1" runat="server" /> | |
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1" ErrorMessage="RequiredFieldValidator" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public partial class OnSubmitControlB : System.Web.UI.UserControl | |
{ | |
protected override void OnPreRender(EventArgs e) | |
{ | |
Page.ClientScript.RegisterOnSubmitStatement(this.GetType(), "DoingSomethingElse", "alert('This alert is registered by OnSubmitControlB');"); | |
base.OnPreRender(e); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public partial class OnSubmitControlB : System.Web.UI.UserControl | |
{ | |
protected override void OnLoad(EventArgs e) | |
{ | |
base.OnLoad(e); | |
Page.ClientScript.RegisterOnSubmitStatement(this.GetType(), "DoingSomethingElse", "alert('This alert is registered by OnSubmitControlB');"); | |
} | |
protected override void OnPreRender(EventArgs e) | |
{ | |
// Let's comment this out also | |
// Page.ClientScript.RegisterOnSubmitStatement(this.GetType(), "DoingSomethingElse", "alert('This alert is registered by OnSubmitControlB');"); | |
base.OnPreRender(e); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="OnSubmitTest.aspx.cs" Inherits="OnSubmitTest" %> | |
<%@ Register Src="OnSubmitControlA.ascx" TagName="OnSubmitControlA" TagPrefix="uc1" %> | |
<%@ Register Src="OnSubmitControlB.ascx" TagName="OnSubmitControlB" TagPrefix="uc2" %> | |
<html xmlns="http://www.w3.org/1999/xhtml" > | |
<head runat="server"> | |
<title>Test Page</title> | |
</head> | |
<body> | |
<form id="form1" runat="server"> | |
<uc1:OnSubmitControlA ID="OnSubmitControlA1" runat="server" /> | |
<uc2:OnSubmitControlB ID="OnSubmitControlB1" runat="server" /> | |
<asp:Button ID="Button1" runat="server" Text="Button" /> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment