ASP .NET中一个可以用来大作文章的地方。
ASP .NET页面的Client端HTML,通常都会有以下脚本。这是一个非常可以利用的地方,通过他,你可以定制你的WebControl在Client端触发什么动作时提交什么数据。
__doPostBack是ASP .NET PAGE在Client端生成的函数,用于触发服务器端WebControl的事件。例如你查看页面,有时候看到类似这样的代码:
其中,'_ctrl0'是一个WebControl的id,第二个参数为调用参数。如果_ctrl0是一个Button,则会调用其Click事件。触发大多数WebControl的服务器端事件不需要参数,个别需要参数,例如复杂的DataGrid。
两种使用方式:
1、在你的自己的WebControl生成代码中调用__doPostPostBack。
2、使用别人的WebControl,调用__doPostPostBack,触发其特定事件。记得以前使用DataGrid这样复杂的WebControl时,经常使用这种技巧。
这个技巧,是恰好有人问起来的才记起来。当年经常用这一技巧,但由于太久没做这方面的开发,所以手头上没有实际的例子。希望有人能够跟帖补充例子,因为这个对自行开发或者使用WebControl的作用是很大。
还是那句话,我希望我的工作对大家有所帮助!
function __doPostBack(eventTarget, eventArgument) {
var theform;
if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
theform = document.forms["Form1"];
}
else {
theform = document.Form1;
}
theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
theform.__EVENTARGUMENT.value = eventArgument;
theform.submit();
}
var theform;
if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
theform = document.forms["Form1"];
}
else {
theform = document.Form1;
}
theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
theform.__EVENTARGUMENT.value = eventArgument;
theform.submit();
}
<a href="javascript:__doPostBack('_ctl0','')">
两种使用方式:
1、在你的自己的WebControl生成代码中调用__doPostPostBack。
2、使用别人的WebControl,调用__doPostPostBack,触发其特定事件。记得以前使用DataGrid这样复杂的WebControl时,经常使用这种技巧。
这个技巧,是恰好有人问起来的才记起来。当年经常用这一技巧,但由于太久没做这方面的开发,所以手头上没有实际的例子。希望有人能够跟帖补充例子,因为这个对自行开发或者使用WebControl的作用是很大。
还是那句话,我希望我的工作对大家有所帮助!