将 OnClick 事件添加到 ASP.NET 控件

Adding OnClick event to ASP.NET control(将 OnClick 事件添加到 ASP.NET 控件)

本文介绍了将 OnClick 事件添加到 ASP.NET 控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的 panel 创建 OnClick 事件.到目前为止,大多数谷歌搜索结果或多或少是这样的:将 onclick 事件添加到 aspnet 标签.有没有办法从 javascript 或面板属性调用代码隐藏函数?因为我想将用户重定向到一个新页面,然后在 ViewSTate 或 Sessionstate 中保存一些信息.有什么建议?

i would like to create OnClick event for my panel. So far now the most of the google results look more or less like this: adding onclick event to aspnet label. Is there any way, to call codebehind function from javascript or panel attributes? Because I would like to Redirect user to a new page and before that save some information in ViewSTate or Sessionstate. Any suggestions?

推荐答案

在您的 java 脚本方法中引发 __dopostback 调用到 服务器端方法.

In your java script method raise a __dopostback call to a Server side method.

<script type="text/javascript">
     function YourFunction()
     {
         __doPostBack('btnTemp', '')
     }
</script>

其中btnTemp是一个服务器端的按钮,所以在服务器端写一个这个按钮的onClick事件,你可以在那里进行处理,然后重定向到其他页面.

Where btnTemp is a server side button, so write a onClick event of this button on server side, where you can do the processing and then redirect to other page.

您可以在 DoPostBack 理解

这篇关于将 OnClick 事件添加到 ASP.NET 控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:将 OnClick 事件添加到 ASP.NET 控件