This is a test page that we add a simple HTML button with an ID of btnSave with some script(Not web form control). No need or 'Run as Server Control'. I added an HTML Hidden control and initialize it in the checkUIEntry() function.
First we force the Page_ClientValidate() function in the WebUIValidation.js file that the framework downloads. If that returns true, then prompt the web visitor to submit the page.
Then, in the Page_Load event, we check for IsPostBack and the value of the Hidden control.
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="testWeb.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<script language="javascript">
function checkUIEntry(){
if(Page_ClientValidate()){
if(confirm("Save?")){
Form1.submitControl.value="saveButton"
document.Form1.submit()
}
}
}
</script>
<form id="Form1" method="post" runat="server">
<asp:textbox id="TextBox1" style="Z-INDEX: 101; LEFT: 128px; POSITION: absolute; TOP: 24px" runat="server"></asp:textbox>
<asp:button id="Button1" style="Z-INDEX: 102; LEFT: 56px; POSITION: absolute; TOP: 80px" runat="server"Text="Button"></asp:button>
<asp:label id="Label1" style="Z-INDEX: 103; LEFT: 40px; POSITION: absolute; TOP: 24px" runat="server">Enter Value:</asp:label>
<asp:requiredfieldvalidator id="RequiredFieldValidator1" style="Z-INDEX: 104; LEFT: 296px; POSITION: absolute; TOP: 24px" runat="server" ControlToValidate="TextBox1" ErrorMessage="Required"></asp:requiredfieldvalidator>
<asp:label id="Label2" style="Z-INDEX: 105; LEFT: 64px; POSITION: absolute; TOP: 48px" runat="server" ForeColor="#0000C0">Label</asp:label>
<INPUT id="btnSave" style="Z-INDEX: 106; LEFT: 240px; POSITION: absolute; TOP: 80px" onclick="checkUIEntry()" type="button" value="Save">
<INPUT id="submitControl" style="Z-INDEX: 107; LEFT: 296px; POSITION: absolute; TOP: 56px" type="hidden" name="Hidden1" runat="server">
</form>
</body>
</HTML>
'******************** CODE BEHIND ******************************************************************
Public Class WebForm1
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents RequiredFieldValidator1 As System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents Label2 As System.Web.UI.WebControls.Label
Protected WithEvents submitControl As System.Web.UI.HtmlControls.HtmlInputHidden
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If IsPostBack Then
viewstate("counter") += 1
Me.Label2.Text = "Posted " & viewstate("counter")
Else
viewstate("counter") = 0
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Page.IsValid Then
Me.Label2.Text = "IsValid"
Else
Me.Label2.Text = "Is Invalid"
End If
End Sub
End Class