問題描述
我想為我的 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 控件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!