这段事件做项目用到在前台调用后台的方法,想起了__doPostBack这个JavaScript方法,在网上搜索了一下,看到了一个重写的通用的__doPostBack方法_doPostBack_Ex。
__doPostBack是一个纯粹并且是非常简单的javascript函数,大部分的页面PostBack都是由它触发的。
<script language="javascript">
<!--
function __doPostBack_Ex(eventTarget, eventArgument)
{
var theform;
if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
theform = document.forms[0];
}
else {
theform = document.forms[0];
}

if(!theform.__EVENTTARGET)
{
theform.appendChild(document.createElement("<input type='hidden' name='__EVENTTARGET'>"));
}
if(!theform.__EVENTARGUMENT)
{
theform.appendChild(document.createElement("<input type='hidden' name='__EVENTARGUMENT'>"));
}
theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
theform.__EVENTARGUMENT.value = eventArgument;
if ((typeof(theform.onsubmit) == "function"))
{
if(theform.onsubmit()!=false)
{
theform.submit();
}
}
else
{
theform.submit();
}
function __doPostBack(eventTarget, eventArgument)
{
__doPostBack_Ex(eventTarget, eventArgument);
}
}
// -->
</script>
调用方法:
function do_postbak()
{
__doPostBack_Ex("btn_OK","");
}
"btn_OK"为后台控件名称。
我还有个功能没有实现,不知那位能不能在上面的基础上给个提示:
我的本意是在新添加一条记录的时候,首先验证该条数据是否在数据库中存在,如果存在则执行return window.confirm("存在相同用户姓名,是否继续?");如果用户点击是,则继续执行向数据库写入数据,如果用户点击否,则返回,不向数据库写入数据。
__doPostBack是一个纯粹并且是非常简单的javascript函数,大部分的页面PostBack都是由它触发的。
<script language="javascript">
<!--
function __doPostBack_Ex(eventTarget, eventArgument)
{
var theform;
if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
theform = document.forms[0];
}
else {
theform = document.forms[0];
}
if(!theform.__EVENTTARGET)
{
theform.appendChild(document.createElement("<input type='hidden' name='__EVENTTARGET'>"));
}
if(!theform.__EVENTARGUMENT)
{
theform.appendChild(document.createElement("<input type='hidden' name='__EVENTARGUMENT'>"));
}
theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
theform.__EVENTARGUMENT.value = eventArgument;
if ((typeof(theform.onsubmit) == "function"))
{
if(theform.onsubmit()!=false)
{
theform.submit();
}
}
else
{
theform.submit();
}
function __doPostBack(eventTarget, eventArgument)
{
__doPostBack_Ex(eventTarget, eventArgument);
}
}
// -->
</script>
function do_postbak()
{
__doPostBack_Ex("btn_OK","");
}我还有个功能没有实现,不知那位能不能在上面的基础上给个提示:
我的本意是在新添加一条记录的时候,首先验证该条数据是否在数据库中存在,如果存在则执行return window.confirm("存在相同用户姓名,是否继续?");如果用户点击是,则继续执行向数据库写入数据,如果用户点击否,则返回,不向数据库写入数据。

浙公网安备 33010602011771号