格上单击执行服务器端code [英] execute serverside code on div click
问题描述
ASPX code
<div id="c" runat="server" onclick="loadContentFamily" onmousedown="loadContentFamily" rel="divUpdatePanel" >Family</div>
服务器端的code
Public Sub loadContentFamily(ByVal PageName As String)
MsgBox("")
PageName = "Family"
Dim _con As New SqlConnection(ConfigurationManager.ConnectionStrings("LeaveDBConnectionString").ConnectionString)
Dim _da As New SqlDataAdapter("SELECT PageHeader,PageContent FROM PageKeeper WHERE PageName='" & PageName & "'", _con)
Dim _table As New DataTable
Try
_con.Open()
_da.Fill(_table)
_con.Close()
_con.Dispose()
With _table.Rows(0)
h4header.InnerText = .Item(0)
divUpdatePanel.InnerHtml = .Item(1)
Me.Title = .Item(0)
End With
Catch ex As Exception
MsgBox(ex.Message)
divUpdatePanel.InnerText = "No Data Found"
Finally
_con.Close()
_con.Dispose()
End Try
End Sub
问题:
当我在它不执行服务器端code在div点击......为什么??任何帮助AP preciated。
When i click on the div it does not execute the ServerSide Code ...why??Any help appreciated.
推荐答案
您需要提高服务器的事件,而不是客户端事件(和它看起来像你想这样做异步)。
You need to raise a server event, not client event (and it looks like you want to do that asynchronously).
本文介绍了如何code的片段连接到客户端元素(如 DIV
),并导致异步回发。
This article explains how to attach a snippet of code to a client element (like a DIV
) and cause an asynchronous postback.
完成此的另一个快速和肮脏的方法是使用一个隐式服务程序按钮。该按钮可以位于任何地方所需的(如内部的的UpdatePanel
),并允许ASP页面生命周期的正确用法。
Another quick and dirty way of accomplishing this is to use a hidden server button. The button can be located wherever desired (such as inside an UpdatePanel
) and it allows proper usage of the ASP page lifecycle.
<asp:Button runat="server" id="btnPostback" style="display:none" onclick="serverEventHandler" />
<div onclick="document.getElementById('<%= btnPostback.ClientID %>').click()">Clickable DIV</div>
这篇关于格上单击执行服务器端code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!