G
Goethals Frederik
hi,
I have a little problem with the function "Page.GetPostBackClientHyperlink".
First some description of my page:
It is a simple testpage for testing "selecting a row af the datagrid by clicking on the whole row". After some googling I thought I found a solution (see code below)
I have a datagrid with 1 Select-column (via the property-building in VS.NET) and some auto-generated colums with data. The "Select-column" is the first column shown in the grid.
I thougt that the code below would do the trick, but the function Page.GetPostBackClientHyperlink(button, "" ) returns javascript:__doPostBack('','')
In the code below I have tested three functions of page.getpostback..., and they return not the correct __doPostback(...) that belongs to the select-linkbutton.
I thought that the button was'n found, but the lines
Dim button As LinkButton = CType(e.Item.Cells(0).Controls(0), LinkButton)
TextBox1.Text &= button.Text
works well and gives me for each row the word "select" witch is the caption/text of the linkbutton.
But the functions to get the wright javascript back doesn't seems to work (and on the internet there the same code without any notion of errors...)
I have fixed the problem (see the commented line of code) by doing some tricks (adding +2 and so..) But I would like to have It worked by the build-in functions, so it will work sure and correct.
Is there someone who can explain why the line
hulp = Page.GetPostBackClientHyperlink(button, "")
give always the wrong javascript ==> return always ==> javascript:__doPostBack('','')
Thank you very much
Frederik
---------------------------------------------------------------
CODE BELOW (code behind, vb.net)
Private Sub DataGrid1_ItemCreated(ByVal sender As Object, ByVal e As DataGridItemEventArgs) Handles DataGrid1.ItemCreated
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.SelectedItem Then
Dim button As LinkButton = CType(e.Item.Cells(0).Controls(0), LinkButton)
TextBox1.Text &= button.Text
TextBox2.Text &= Page.GetPostBackClientHyperlink(button, "")
TextBox3.Text = Page.GetPostBackEventReference(button)
TextBox3.Text &= Page.GetPostBackClientHyperlink(button, "")
TextBox3.Text &= Page.GetPostBackClientEvent(button, "")
e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='beige';this.style.cursor='hand'")
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='white';")
'e.Item.Attributes.Add("onclick", "javascript:__doPostBack('" & "DataGrid1$_" & "ctl" & Str(e.Item.ItemIndex + 2).Trim & "$_ctl0','')")
Dim hulp As String
hulp = Page.GetPostBackClientHyperlink(button, "")
e.Item.Attributes.Add("onclick", hulp)
End If
End Sub
I have a little problem with the function "Page.GetPostBackClientHyperlink".
First some description of my page:
It is a simple testpage for testing "selecting a row af the datagrid by clicking on the whole row". After some googling I thought I found a solution (see code below)
I have a datagrid with 1 Select-column (via the property-building in VS.NET) and some auto-generated colums with data. The "Select-column" is the first column shown in the grid.
I thougt that the code below would do the trick, but the function Page.GetPostBackClientHyperlink(button, "" ) returns javascript:__doPostBack('','')
In the code below I have tested three functions of page.getpostback..., and they return not the correct __doPostback(...) that belongs to the select-linkbutton.
I thought that the button was'n found, but the lines
Dim button As LinkButton = CType(e.Item.Cells(0).Controls(0), LinkButton)
TextBox1.Text &= button.Text
works well and gives me for each row the word "select" witch is the caption/text of the linkbutton.
But the functions to get the wright javascript back doesn't seems to work (and on the internet there the same code without any notion of errors...)
I have fixed the problem (see the commented line of code) by doing some tricks (adding +2 and so..) But I would like to have It worked by the build-in functions, so it will work sure and correct.
Is there someone who can explain why the line
hulp = Page.GetPostBackClientHyperlink(button, "")
give always the wrong javascript ==> return always ==> javascript:__doPostBack('','')
Thank you very much
Frederik
---------------------------------------------------------------
CODE BELOW (code behind, vb.net)
Private Sub DataGrid1_ItemCreated(ByVal sender As Object, ByVal e As DataGridItemEventArgs) Handles DataGrid1.ItemCreated
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.SelectedItem Then
Dim button As LinkButton = CType(e.Item.Cells(0).Controls(0), LinkButton)
TextBox1.Text &= button.Text
TextBox2.Text &= Page.GetPostBackClientHyperlink(button, "")
TextBox3.Text = Page.GetPostBackEventReference(button)
TextBox3.Text &= Page.GetPostBackClientHyperlink(button, "")
TextBox3.Text &= Page.GetPostBackClientEvent(button, "")
e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='beige';this.style.cursor='hand'")
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='white';")
'e.Item.Attributes.Add("onclick", "javascript:__doPostBack('" & "DataGrid1$_" & "ctl" & Str(e.Item.ItemIndex + 2).Trim & "$_ctl0','')")
Dim hulp As String
hulp = Page.GetPostBackClientHyperlink(button, "")
e.Item.Attributes.Add("onclick", hulp)
End If
End Sub