如何为listitem创建事件 [英] How to create events for listitem

查看:85
本文介绍了如何为listitem创建事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经退出了listitem..

I have my logout in listitem..

<li  ><a>Log Out</a></li>



我需要在单击注销时编写注销功能..

我已经这样尝试过了.



I need to write log out functionality on clicking log out..

I have tried like this..

<li onclick="logout" ><a>Log Out</a></li>





protected void logout(object sender, EventArgs e)
   {

       Session.Clear();
       Response.Redirect("login.aspx");

   }



但是它不起作用..

怎么做..

在此先感谢..



But its not working..

How to do this..

thanks in advance..

推荐答案

朋友您好,请尝试以下操作:
Hello friend, try this:
<a href="logout.aspx">Log Out</a>


添加一个新网页- logout.aspx 并在Page_Load()事件中编写以下代码:


Add a new web page - logout.aspx and write the below code in Page_Load() event:

//Cancels current session
Session.Abandon();
Response.Redirect("login.aspx");


OnClick 事件添加为logout并包含runat="server"

add OnClick event as logout and include runat="server"

<li  runat="server"  OnClick="logout">Log Out</li>


Hello Priya Darshan,

通过客户端元素调用服务器方法显然是失败的尝试.

您正在使用客户端html元素作为列表,该列表是
Hello Priya Darshan,

It is a obvious fail attempt to call a server method through client side element.

You are using client side html elements as list which is a
<li>

元素,因此您只能在JavaScript中调用客户端方法.

在您的情况下,您可以在JavaScript中调用此页面方法进行ajax调用(请使用jquery

element, so you have to call a client-side method only in JavaScript.

In your case you can call this page method in JavaScript making a ajax call (check with jquery

.ajax()

方法进行检查.),然后在列表项click中调用该方法. br/>
否则,您可以创建要通过JavaScript调用的网络方法,然后在列表项中单击该方法.

再次向li元素添加click事件处理程序,向该元素添加一个ID,让我们说"liTest",现在添加如下的click事件:-

method.), then call that method in the list item click.

OR else you can create a web method to be called through JavaScript, then call that method in the list item click.

Again to add click event handler to li element add a ID to that element let say ''liTest'', now add the click event as below :-


这篇关于如何为listitem创建事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆