类比LinkButton按钮
LinkButton前台生成代码:
JS代码:
//<![CDATA[
var theForm = document.forms['form1'];
if (!theForm) {
theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
//]]>
控件代码:
<a id="LinkButton1" class="dispaly:none" href="javascript:__doPostBack("控件Name或id属性"," ")"></a>
综上可以看出:a标签可以调用后台方法,同理button标签,同样可以,但要做如下操作:
1.拖一button标签
2.添加Onclick时间
3.模拟LinkBotton控件
JS代码:
window.onload = function () {
document.getElementById("click").onclick = htmlClick;
}
function htmlClick() { __doPostBack("btn_click","");
}
此时相应的__doPostBack函数,可以通过拖一个Linkbutton控件获得,直接调用就行。 控件代码:
<input type="submit" name="btn_click" value="服务器控件" id="btn_click" />
<input type="button" id="click" value="HTML控件" />
。。。。
参考链接:
工作经验:http://www.cnblogs.com/Silicon-Fado/archive/2009/04/19/1439088.html
__doPostBack方法分析:http://www.cnblogs.com/Silicon-Fado/archive/2009/04/21/1440437.html