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 控件


基础教程推荐
- C# 9 新特性——record的相关总结 2023-04-03
- 获取C#保存对话框的文件路径 2022-01-01
- 从 C# 控制相机设备 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- 如果条件可以为空 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- 将数据集转换为列表 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01