Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Handling a Click Event
Message
From
22/11/2003 02:39:36
Keith Payne
Technical Marketing Solutions
Florida, United States
 
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00852578
Message ID:
00852580
Views:
8
>I know I am a newbie to .net and maybe it's just late but I am trying to handle a click event on the server side but I am having a problem.
>
>First example works fine but it only call the js funtion and not my server side function. Here i am adding the event attribute ("onClick") to the control at ItemDataBound of my datagrid.
>
Private Sub TimeEntryGrid_Itembound(ByVal sender As System.Object,_
> ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) _
> Handles TimeEntryGrid.ItemDataBound
>
> If (e.Item.ItemType) = ListItemType.Item Or _
> (e.Item.ItemType) = ListItemType.AlternatingItem Then
>       e.Item.Attributes("onClick") = "javascript:return confirm ( 'Edit this entry?' )"
> End If
> End Sub 'TimeEntryGrid_Itembound
>
>But when I call a server side function it doesn't work, no errors.
>
Private Sub TimeEntryGrid_Itembound(ByVal sender As System.Object,_
> ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) _
> Handles TimeEntryGrid.ItemDataBound
>
> If (e.Item.ItemType) = ListItemType.Item Or _
> (e.Item.ItemType) = ListItemType.AlternatingItem Then
>       e.Item.Attributes("onClick") = "clientfunction();"
> End If
> End Sub 'TimeEntryGrid_Itembound
>
>
>Can I call a Server side function using JS like?
>
e.Item.Attributes("onClick") = "javascript:jsfunction();"
>
>But then how do I call the Server side funtion from inside the js
>
<script language="javascript">
>  function jsfunction()
>  {
>     'Call clientfunction() here?
>  }
>  </script>
>
>Can I call a server function from the client in JS?

James,

You can't call a server side function from client-side javascript, and you can't call a client-side javascript function from the server. The reason is that all of the server side execution happens _before_ the HTML is sent to the browser.

If you assign the OnClick attribute of an HTML or asp element, the server-side click event is not raised.

What you can do is add your script code to the Response stream during the postback so that it is executed when the HTML is sent to the browser. You can do this with Response.Write or Page.RegisterClientStartupScript.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform