problems with " Page.GetPostBackClientHyperlink() "

  • Thread starter Goethals Frederik
  • Start date
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
 
B

bruce barker

the default link button is rendered as a submit and does not use and javascript. as submit buttons do not have a command name, the value returned is "". you need set command name to the link button for it to work in the manner you want.

-- bruce (sqlwork.com)




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
 
G

Goethals Frederik

hmm,

The linkbutton I use is the one that is generated by the datagrid property-builder in VS.net 2003.
I just checked the linkbutton and the command name has been filled in with "Select" Without the quotes.
The datagrid works fine when i just click on the select-linkbutton (the selectcommand is fired (itemcommand en selectedindex_changed...). and the select-linkbutton uses some javascript __dopostback to postback the grid to the server.

I find it very strange because I just followed the instructions from several website and google-groups. They all say that it has to work with the following code


Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) _
Handles DataGrid1.ItemDataBound
Dim itemType As ListItemType = e.Item.ItemType
If ((itemType = ListItemType.Pager) Or _
(itemType = ListItemType.Header) Or _
(itemType = ListItemType.Footer)) Then
Return
Else
Dim button As LinkButton = _
CType(e.Item.Cells(0).Controls(0), LinkButton)
e.Item.Attributes("onclick") = _
Page.GetPostBackClientHyperlink(button, "")
End If
End Sub

but that doesn't work with me. And yes, the default-buit-in-select-linkbutton is in the first colomn of the grid...

Any suggestions

thx

frederik





"bruce barker" <[email protected]> schreef in bericht the default link button is rendered as a submit and does not use and javascript. as submit buttons do not have a command name, the value returned is "". you need set command name to the link button for it to work in the manner you want.

-- bruce (sqlwork.com)




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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top