[英]How to call asp function on onclick event?
I want to call one asp function on onclick event. 我想在onclick事件上调用一个asp函数。
<img src="..." style="cursor: pointer;" onclick="..." />
Here at onclick
I want to call following function: 在
onclick
我想调用以下函数:
function getproject(valuenew)
response.Cookies("projectname") = valuenew
end function
How should I do this? 我应该怎么做?
It does not make sense to return to the server to set a cookie. 返回服务器设置cookie没有任何意义。 You can set a cookie very easily using JavaScript.
您可以使用JavaScript轻松设置Cookie。 Here is an example:
这是一个例子:
var expire = new Date();
expire.setTime(today.getTime() + 3600000*24*5); // expire in 5 days
document.cookie="projectname=valuenew;expires=" +expire.toGMTString();
Here is a link with more info: http://www.w3schools.com/js/js_cookies.asp 这是更多信息的链接: http : //www.w3schools.com/js/js_cookies.asp
You don't have to use ASP to set cookie, but I'll give you simple way to execute ASP code after clicking element. 您不必使用ASP来设置cookie,但是我将为您提供一种简单的方法,在单击element之后执行ASP代码。
First, add hidden frame to your page: 首先,将隐藏的框架添加到您的页面:
<iframe id="ajaxFrame" src="about:blank" style="display: none;"></iframe>
Now in the onclick
have this: 现在在
onclick
有以下内容:
onclick="document.getElementById('ajaxFrame').src = 'PageNameHere.asp?cookievalue=Your_New_Value_Here';"
And the last step, add this to your ASP code: (on top) 最后一步,将其添加到您的ASP代码中:(在顶部)
If Request.QueryString("cookievalue")<>"" Then
getproject(Request.QueryString("cookievalue"))
Response.END
End If
This is not the best practice, but as you're a beginner it's the most simple way I know of.. when you gain some experience look into real AJAX, most simple and powerful is jQuery AJAX . 这不是最佳实践,但是作为一个初学者,这是我所知道的最简单的方法..当您获得一些真正的AJAX经验时,最简单,最强大的就是jQuery AJAX 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.