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)
{

  .....

}

posted on 2011-05-25 10:07  秋天  阅读(1177)  评论(1编辑  收藏  举报

导航