javascript中要触发CS后台中的某个方法或事件
1.触发方法
html:
<a href="javascript:void(0);" id="A1" onclick="delete()" class="btn_01 btn_02 btn_edit"><span>删除</span> </a>
js:
<script type="text/javascript">
function delete()
{
__doPostBack("__Delete", "")
}
</script>
CS:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
.......
}
if ("__Delete" == Request.Params["__EVENTTARGET"])
{
Delete();
}
}
private void Delete()
{
....
}
2.触发后台事件.
html:
<a href="javascript:void(0);" id="A1" onclick="delete()" class="btn_01 btn_02 btn_edit"><span>删除</span> </a>
<asp:LinkButton ID="lbtnDelete" runat="server" OnClick="lbtnDelete_Click"></asp:LinkButton>
js:
<script type="text/javascript">
function delete()
{
document.getElementById("<%= this.lbtnDelete.ClientID %>").click(); }
</script>
CS:
protected void lbtnDelete_Click(object sender, EventArgs e)
{
.....
}