amandajdarlow
asked on
How to call a function on the onclick of a DevExpress pivot grid cell click
I currently have the following which works perfectly. This sets the onclick event of a DevExpress pivot grid cell click to open a new window.
I would like to change it so that it calls a function rather than opening a new window. So I tried the following
However this causes the function to run at the time this sub is executed rather than when the user clicks on the cell. I need the function to execute when the user clicks on the cell in the pivot grid.
This code is all embedded in the below which I have put in for completeness.
Can you please tell me where I'm going wrong.
Thanks.
Public Sub New(text As String, strEpisodes As String, values As List(Of Object))
Dim tagURL As String
If text <> String.Empty Then
Me.NavigateUrl = "#"
tagURL = "window.open('SessionTagNotes.aspx?tag=" & text & "&episodes=" & strEpisodes & "', 'winTagNotes', 'directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,titlebar=no,toolbar=no,top=5,left=0,height=500,width=800', true);"
Attributes("onclick") = tagURL
End If
End Sub
I would like to change it so that it calls a function rather than opening a new window. So I tried the following
Public Sub New(text As String, strEpisodes As String, values As List(Of Object))
Dim tagURL As String
If text <> String.Empty Then
tagURL = TWSLibrary.TagGridNotes(text, strEpisodes)
Attributes("onclick") = tagURL
End If
End Sub
However this causes the function to run at the time this sub is executed rather than when the user clicks on the cell. I need the function to execute when the user clicks on the cell in the pivot grid.
This code is all embedded in the below which I have put in for completeness.
Can you please tell me where I'm going wrong.
Thanks.
Imports DevExpress.Web.ASPxPivotGrid
Imports DevExpress.XtraPivotGrid.Data
Public Class FieldValueTemplate
Implements ITemplate
Public Sub InstantiateIn(control As System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn
Dim c As PivotGridFieldValueTemplateContainer = DirectCast(control, PivotGridFieldValueTemplateContainer)
Dim cell As PivotGridFieldValueHtmlCell = c.CreateFieldValue()
Dim valueItem As PivotFieldValueItem = c.ValueItem
Dim helperArgs As PivotFieldValueEventArgs = New PivotFieldValueEventArgs(valueItem)
Dim fields() As PivotGridField = helperArgs.GetHigherLevelFields()
For Each field As PivotGridField In fields
Dim currentValue As Object = helperArgs.GetHigherLevelFieldValue(field)
If cell.TextControl.Text = "" Then
cell.Controls.AddAt(cell.Controls.IndexOf(cell.TextControl), New LiteralControl(c.Text))
cell.Controls.Remove(cell.TextControl)
End If
c.Controls.Add(cell)
Next
End Sub
End Class
Public Class CellTemplate
Implements ITemplate
Dim strEpisodes As String
Sub New(Episodes As String)
strEpisodes = Episodes
End Sub
Public Sub InstantiateIn(container As Control) Implements ITemplate.InstantiateIn
Dim c As PivotGridCellTemplateContainer = DirectCast(container, PivotGridCellTemplateContainer)
Dim fieldValues As List(Of Object) = New List(Of Object)
If Not IsNothing(c.ColumnField) Then
fieldValues.Add(c.GetFieldValue(c.ColumnField))
End If
If Not IsNothing(c.RowField) Then
fieldValues.Add(c.GetFieldValue(c.RowField))
End If
If c.Text.Contains(",") Then
Dim strTagArr() As String = c.Text.Split(",")
For Each strTag As String In strTagArr
c.Controls.Add(New MyLink(strTag, strEpisodes, fieldValues))
Next
Else
c.Controls.Add(New MyLink(c.Text, strEpisodes, fieldValues))
End If
End Sub
End Class
Public Class MyLink
Inherits HyperLink
Public Sub New(text As String, strEpisodes As String, values As List(Of Object))
Dim tagURL As String
If text <> String.Empty Then
tagURL = TWSLibrary.TagGridNotes(text, strEpisodes)
Attributes("onclick") = tagURL
text = String.Empty
End If
End Sub
End Class
ASKER
It is a vb.net function which simply sets two session variables. Can this be done in javascript?
Session is a server side structure so you cannot directly set it in JavaScript. What you can do is call the server side method in JavaScript.
Examples
http://www.morgantechspace.com/2014/01/Call-Server-Side-function-from-JavaScript-in-ASP-NET.html
http://www.c-sharpcorner.com/UploadFile/rohatash/calling-server-side-function-from-javascript-in-Asp-Net/
Examples
http://www.morgantechspace.com/2014/01/Call-Server-Side-function-from-JavaScript-in-ASP-NET.html
http://www.c-sharpcorner.com/UploadFile/rohatash/calling-server-side-function-from-javascript-in-Asp-Net/
ASKER
I decide to write a Javascript function which assigned the required value to a hidden field instead of trying to set a Session Variable.
However I cannot get the Javascript function to execute.
The JS function is this.
function UpdateTagNotes(intTagId) {
document.getElementById('h dnTagGridT agId').val ue = intTagId;
alert("Hi");
}
The calling code is this
tagURL = "UpdateTagNotes(" & intTagId & ");"
Attributes("onclick") = tagURL
or this
tagURL = "Page.ClientScript.Registe rClientScr iptBlock(M e.GetType, 'UpdateTagNotes', '<script language='javascript'>Upda teTagNotes (" & intTagId & ");</script>')"
Attributes("onclick") = tagURL
neither works.
Any thoughts? I am tearing my hair out.
Thanks
However I cannot get the Javascript function to execute.
The JS function is this.
function UpdateTagNotes(intTagId) {
document.getElementById('h
alert("Hi");
}
The calling code is this
tagURL = "UpdateTagNotes(" & intTagId & ");"
Attributes("onclick") = tagURL
or this
tagURL = "Page.ClientScript.Registe
Attributes("onclick") = tagURL
neither works.
Any thoughts? I am tearing my hair out.
Thanks
Does changing
tagURL = "UpdateTagNotes(" & intTagId & ");"
to
tagURL = "Javascript:UpdateTagNotes (" & intTagId & ");"
help?
tagURL = "UpdateTagNotes(" & intTagId & ");"
to
tagURL = "Javascript:UpdateTagNotes
help?
ASKER
Nope still not working.
However if I add
function UpdateTagNotes() {
hdnTagGridTagId.Set("TagId ", "999");
}
function GetValue() {
alert(hdnTagGridTagId.Get( "TagId"));
}
and
<a href="javascript:GetValue( )">Get value</a>
<a href="javascript:UpdateTag Notes()">S et value</a>
then these button call the functions no problem.
But the line
ClientScript.RegisterClien tScriptBlo ck(Me.GetT ype, "debtnLstTagGrid_SelectedI ndexChange d", "<script language='javascript'>Upda teTagNotes (1);</scri pt>")
won't work either!?!?!?!
Many thanks for your help.
However if I add
function UpdateTagNotes() {
hdnTagGridTagId.Set("TagId
}
function GetValue() {
alert(hdnTagGridTagId.Get(
}
and
<a href="javascript:GetValue(
<a href="javascript:UpdateTag
then these button call the functions no problem.
But the line
ClientScript.RegisterClien
won't work either!?!?!?!
Many thanks for your help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
At last it is all working.
Turned out to be a combination of DevExpress settings which was causing the problem. Javascript was fine all along.
Many thanks for all the help.
Turned out to be a combination of DevExpress settings which was causing the problem. Javascript was fine all along.
Many thanks for all the help.
ASKER
All your help was much appreciated.
Glad you got it working :-)
tagURL = TWSLibrary.TagGridNotes(te
to
tagURL = "TWSLibrary.TagGridNotes(t
If its a VB.NET function on the server side then it will need to a bit more work to relay the client side click to the server.