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

question regarding __doPostBack

P: n/a
Hello,
I am trying to create a postback event, and it is working, just not calling
the sub.
I have a datagrid which has
<asp:DataGrid id="Mensajes"
...
<Columns>
<asp:HyperLinkColumn
....

DataNavigateUrlFormatString="javascript:__doPostBa ck('loadMessage','{0}')"

I also placed the following javascript function:
function __doPostBack(eventTarget, eventArgument) {
var theform;
if (window.navigator.appName.toLowerCase().indexOf("n etscape")
-1) {

theform = document.forms["_ctl0"];
}
else {
theform = document._ctl0;
}
theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
theform.__EVENTARGUMENT.value = eventArgument;
theform.submit();
}
In the Sub Page_Load
I have
response.write ("__EVENTTARGET " & request("__EVENTTARGET") & "<br>")
response.write ("__EVENTARGUMENT " & request("__EVENTARGUMENT") & "<br>")

and I do receive both parameters, but the sub 'loadMessage' never gets
called.
Right now I patched it using a switch/case __EVENTTARGET then calling the
sub "manually".

What did I miss?

Thanks

Nov 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
First, instead or creating the _postback javascript code yourself, you'd
better use :

myHref = Page.GetPostBackClientHyperlink(myControl, myArgs)

The problem or your code is that the first argument of __doPostBack should
not be the name of a sub, but the name of the control that fired the
postback event.

To solve your problem, you'd better use a BoundColumn instead of a
HyperLinkColumn:

<asp:BoundColumn onDataBinding="myColumn_DataBinding" />

Sub myColumn_DataBinding(sender As Object, e As EventArgs)
Dim cell As TableCell = CType(sender, TableCell)
Dim oLink As New LinkButton()
cell.Controls.Add(oLink)
oLink.Text = "Click me"
AddHandler oLink.Click, AddressOf loadMessage
End Sub

Sub loadMessage
End Sub

Hope it helps

Henri
"Marcelo" <ma********@spam.stgo.cl> a écrit dans le message de
news:%2****************@tk2msftngp13.phx.gbl...
Hello,
I am trying to create a postback event, and it is working, just not calling the sub.
I have a datagrid which has
<asp:DataGrid id="Mensajes"
...
<Columns>
<asp:HyperLinkColumn
....

DataNavigateUrlFormatString="javascript:__doPostBa ck('loadMessage','{0}')"

I also placed the following javascript function:
function __doPostBack(eventTarget, eventArgument) {
var theform;
if (window.navigator.appName.toLowerCase().indexOf("n etscape")
-1) { theform = document.forms["_ctl0"];
}
else {
theform = document._ctl0;
}
theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
theform.__EVENTARGUMENT.value = eventArgument;
theform.submit();
}
In the Sub Page_Load
I have
response.write ("__EVENTTARGET " & request("__EVENTTARGET") & "<br>")
response.write ("__EVENTARGUMENT " & request("__EVENTARGUMENT") &

"<br>")
and I do receive both parameters, but the sub 'loadMessage' never gets
called.
Right now I patched it using a switch/case __EVENTTARGET then calling the
sub "manually".

What did I miss?

Thanks


Nov 19 '05 #2

P: n/a
Hello,
Thanks for your help, I am having some problems implementing this code,
these are the error messages I am getting:

<asp:BoundColumn onDataBinding="myColumn_DataBinding" />
onDataBinding is not a property of a column, it can only be added to the
code of the dataGrid.

Dim cell As TableCell = CType(sender, TableCell)
gives me the error: System.InvalidCastException: Specified cast is not
valid.

Thanks.
----- Original Message -----
From: "Henri" <hm********@hotmail.com>
Newsgroups: microsoft.public.dotnet.framework.aspnet
Sent: Saturday, December 11, 2004 2:06 PM
Subject: Re: question regarding __doPostBack

First, instead or creating the _postback javascript code yourself, you'd
better use :

myHref = Page.GetPostBackClientHyperlink(myControl, myArgs)

The problem or your code is that the first argument of __doPostBack should
not be the name of a sub, but the name of the control that fired the
postback event.

To solve your problem, you'd better use a BoundColumn instead of a
HyperLinkColumn:

<asp:BoundColumn onDataBinding="myColumn_DataBinding" />

Sub myColumn_DataBinding(sender As Object, e As EventArgs)
Dim cell As TableCell = CType(sender, TableCell)
Dim oLink As New LinkButton()
cell.Controls.Add(oLink)
oLink.Text = "Click me"
AddHandler oLink.Click, AddressOf loadMessage
End Sub

Sub loadMessage
End Sub

Hope it helps

Henri
"Marcelo" <ma********@spam.stgo.cl> a écrit dans le message de
news:%2****************@tk2msftngp13.phx.gbl...
Hello,
I am trying to create a postback event, and it is working, just not

calling
the sub.
I have a datagrid which has
<asp:DataGrid id="Mensajes"
...
<Columns>
<asp:HyperLinkColumn
....

DataNavigateUrlFormatString="javascript:__doPostBa ck('loadMessage','{0}')"
I also placed the following javascript function:
function __doPostBack(eventTarget, eventArgument) {
var theform;
if (window.navigator.appName.toLowerCase().indexOf("n etscape")
-1) {

theform = document.forms["_ctl0"];
}
else {
theform = document._ctl0;
}
theform.__EVENTTARGET.value = eventTarget.split("$").join(":"); theform.__EVENTARGUMENT.value = eventArgument;
theform.submit();
}
In the Sub Page_Load
I have
response.write ("__EVENTTARGET " & request("__EVENTTARGET") & "<br>")
response.write ("__EVENTARGUMENT " & request("__EVENTARGUMENT") &

"<br>")

and I do receive both parameters, but the sub 'loadMessage' never gets
called.
Right now I patched it using a switch/case __EVENTTARGET then calling the sub "manually".

What did I miss?

Thanks


Nov 19 '05 #3

P: n/a
Sorry, I forgot an important part of the code:
You have to create your custom BoundColumn declaring a class that inherits
BoundColumn:

'*******************************************
NameSpace MyNameSpace

Public Class MyBoundColumn
Inherits System.Web.UI.WebControls.BoundColumn

Public Event DataBinding As EventHandler

Public Overrides Sub InitializeCell(ByVal cell As TableCell, ByVal
columnIndex As Integer, ByVal itemType As ListItemType)
MyBase.InitializeCell(cell, columnIndex, itemType)
Select Case itemType
Case ListItemType.Item, ListItemType.AlternatingItem
AddHandler cell.DataBinding, AddressOf CreateItem
End Select

End Sub

Private Sub CreateItem(ByVal sender As Object, ByVal e As EventArgs)
Dim cell As TableCell = CType(sender, TableCell)
RaiseEvent DataBinding(cell, EventArgs.Empty)

End Sub

End Class

End NameSpace
'************************************************* *****************

Compile this class in MyAssembly.dll and put it in your .bin directory

Then in your .aspx page :

<%@ Register TagPrefix="myprefix" Namespace="myNameSpace"
Assembly="MyAssembly" %>

......

<asp:DataGrid .... >
...
<myprefix:MyBoundColumn onDataBinding="myColumn_DataBinding" />
...
</asp:DataGrid>
If you need more information about custom columns, try:
http://msdn.microsoft.com/library/de...tomcolumns.asp

Hope it helps

Henri
"Marcelo" <ma********@spam.stgo.cl> a écrit dans le message de
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hello,
Thanks for your help, I am having some problems implementing this code,
these are the error messages I am getting:

<asp:BoundColumn onDataBinding="myColumn_DataBinding" />
onDataBinding is not a property of a column, it can only be added to the code of the dataGrid.

Dim cell As TableCell = CType(sender, TableCell)
gives me the error: System.InvalidCastException: Specified cast is not
valid.

Thanks.
----- Original Message -----
From: "Henri" <hm********@hotmail.com>
Newsgroups: microsoft.public.dotnet.framework.aspnet
Sent: Saturday, December 11, 2004 2:06 PM
Subject: Re: question regarding __doPostBack

First, instead or creating the _postback javascript code yourself, you'd
better use :

myHref = Page.GetPostBackClientHyperlink(myControl, myArgs)

The problem or your code is that the first argument of __doPostBack should
not be the name of a sub, but the name of the control that fired the
postback event.

To solve your problem, you'd better use a BoundColumn instead of a
HyperLinkColumn:

<asp:BoundColumn onDataBinding="myColumn_DataBinding" />

Sub myColumn_DataBinding(sender As Object, e As EventArgs)
Dim cell As TableCell = CType(sender, TableCell)
Dim oLink As New LinkButton()
cell.Controls.Add(oLink)
oLink.Text = "Click me"
AddHandler oLink.Click, AddressOf loadMessage
End Sub

Sub loadMessage
End Sub

Hope it helps

Henri
"Marcelo" <ma********@spam.stgo.cl> a écrit dans le message de
news:%2****************@tk2msftngp13.phx.gbl...
Hello,
I am trying to create a postback event, and it is working, just not

calling
the sub.
I have a datagrid which has
<asp:DataGrid id="Mensajes"
...
<Columns>
<asp:HyperLinkColumn
....

DataNavigateUrlFormatString="javascript:__doPostBa ck('loadMessage','{0}')"
I also placed the following javascript function:
function __doPostBack(eventTarget, eventArgument) {
var theform;
if (window.navigator.appName.toLowerCase().indexOf("n etscape") > -1) {
theform = document.forms["_ctl0"];
}
else {
theform = document._ctl0;
}
theform.__EVENTTARGET.value = eventTarget.split("$").join(":"); theform.__EVENTARGUMENT.value = eventArgument;
theform.submit();
}
In the Sub Page_Load
I have
response.write ("__EVENTTARGET " & request("__EVENTTARGET") & "<br>") response.write ("__EVENTARGUMENT " & request("__EVENTARGUMENT") &

"<br>")

and I do receive both parameters, but the sub 'loadMessage' never gets
called.
Right now I patched it using a switch/case __EVENTTARGET then calling the sub "manually".

What did I miss?

Thanks




Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.