By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,341 Members | 1,395 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,341 IT Pros & Developers. It's quick & easy.

problems with " Page.GetPostBackClientHyperlink() "

P: n/a

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.cur sor='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

Nov 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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)

"Goethals Frederik" <ivpv_remove_me@remove_me_belgacom.net> wrote in message news:40***********************@news.skynet.be...

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.cur sor='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

Nov 18 '05 #2

P: n/a
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" <no***********@safeco.com> schreef in bericht news:%2***************@tk2msftngp13.phx.gbl...
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)

"Goethals Frederik" <ivpv_remove_me@remove_me_belgacom.net> wrote in message news:40***********************@news.skynet.be...

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.cur sor='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

Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.