Thanks for your reply Tim,
Now I've got that the problem is actually due to the changing of the
ASP.NET button's postback mechanism.
As you have found, in ASP.NET 2.0 pages, the Button has exposed a
"OnClientClick" property to set client-side onclick script handler. And the
runtime emit a "WebForm_DoPostbackWithOptions" function to replace the
original "__doPostback" function in 1.0. Also, the built-in script is no
longer placed in a shared public folder but rendered out through a resource
handler(webresource.axd)...
Actually you can still manually request the resource content through the
generated url, such as:
<script
src="/ASPNET/V2/WebSites/NewTestSite/WebResource.axd?d=yDa86RJ5BlmQizOjOSj4H
M3nrNOaEBU0Q3mZezasA2o1&t=632882923848905939"
type="text/javascript"></script>
You can pick the url out and directly access it in brower and get the
jscript content. I've performed some overview on the built-in scripts.
"WebForm_DoPostbackWithOptions" function will take a single parameter of
"Webform_PostBackOption" which contains several constructor params. The
first is the name of the element which trigger the postback. The last is a
boolean, indicate whether the function need to explicitly call form.submit
(for submit button, this is always false). e.g.
==============
WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("btnSubmit", "",
true, "", "", false, false));
==============
I've tested in my own button's "OnClientClick" and find that we can call it
manually in our client-script to trigger the page's client-side vailadtion,
and then check the "Page_Isvalid" global script variable to determine
whether the page has validation error. If there is no error, we let it go,
else wise, we stop our "smart button"'s client-side behavior.
I've created a test page to demonstrate the work, I've attached the page's
files in this message. You can get it if you're using outlook express to
access the newsgroup. If necessary, I can send you via email.
I'll also paste the page's aspx and codebehind here:
#btw, I use a hidden disabled button instead of disabling the real button
since this can avoid additional work to set POSTBACK arguments
===========aspx==================
<html xmlns="
http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script id="btn_script" language="javascript">
function btn_click(btn)
{
WebForm_DoPostBackWithOptions(new
WebForm_PostBackOptions("btnSubmit", "", true, "", "", false, false));
if(!Page_IsValid)
{
return false;
}
btn.style.display = "none";
document.getElementById(btn.id + "Fake").style.display = "";
return true;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
runat="server" ControlToValidate="TextBox1"
ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
<asp:Button ID="btnSubmit" runat="server" Text="Normal Submit
Button" OnClick="btnSubmit_Click" />
<br />smart button <br />
<hr /><br />
<span>
<asp:Button ID="btnSmart" runat="server" Text="Smart Button"
OnClick="btnSmart_Click" OnClientClick="btn_click(this);" />
<asp:Button ID="btnSmartFake" runat="server" Text="Smart Button"
Enabled="false" style="display:none" />
</span>
</div>
</form>
</body>
</html>
==========code behind================
public partial class ControlPages_TestButtonPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
Response.Write("<br/>Normal button postback........");
}
protected void btnSmart_Click(object sender, EventArgs e)
{
Thread.Sleep(2000);
Response.Write("<br/>Smart button postback........");
}
}
=============================================
Hope this helps.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.