Adding OnClick event to ASP.NET control(将 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 控件
基础教程推荐
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
