ASP.NET 1.1 Converted Projet : Datagrid problem

O

Olivier Matrot

Hello,
I've converted an existing ASP.NET 1.1 project to Visual Studio 2005.
There is a problem with the Datagrid control. The Update & Cancel commands
are not working anymore (Edit is working).

Ive noticed that the postback generated javascript has changed since
ASP.NET 1.1. For Example in ASP.NET 1.1, the Updade shortcut
is "javascript:__doPostBack('dgReceivedHistory$_ctl3$lbValidate','')"
In 2.0 it is now "javascript:__doPostBack('lbValidate','')".
The main differences is that there is no more reference to the datagrid in
the client ID of the control...

Any help apreciated.
TIA.
 
O

Olivier Matrot

Hi Steven,

After looking at your sample, here are my comments :
1) I'm not using an AutogeneratedColumns datagrid.
2) Bound columns are converted into templates to be customized.
3) I'm not using the ItemCommand Event Handler.

I 'll try to reproduce the problem with your page.
In the meantime, here are some additonnal informations :

Here is the datagrid tag :
<asp:datagrid id="dgReceivedHistory" runat="server" Font-Names="Arial"
Font-Size="8pt" AllowSorting="True"
GridLines="None" AllowPaging="True" AutoGenerateColumns="False"
CellPadding="5" BorderStyle="None" PageSize="15"
Height="10px" meta:resourcekey="dgReceivedHistoryResource1">

Here is te converted datagrid template column :

<asp:TemplateColumn SortExpression="Edit">
<HeaderStyle Wrap="False"></HeaderStyle>
<ItemStyle Wrap="False"></ItemStyle>
<ItemTemplate>
<asp:ImageButton id="ibModify" runat="server"
ImageUrl="img/modify.gif" CommandName="Edit" ToolTip="Modifier l'objet"
CausesValidation="False"
meta:resourcekey="ibModifyResource1"></asp:ImageButton>
</ItemTemplate>
<FooterStyle Wrap="False"></FooterStyle>
<EditItemTemplate>
<asp:LinkButton onkeypress="if((event.which && event.which ==
13) || (event.keyCode && event.keyCode == 13))
{ClickButton(event,'lbtnSubmit');return(false);}"
id="lbValidate" runat="server" Text="Valider"
CommandName="Update"
meta:resourcekey="lbValidateResource1"></asp:LinkButton>
<asp:LinkButton id="lbCancel" runat="server" Text="Annuler"
CommandName="Cancel" CausesValidation="False"
meta:resourcekey="lbCancelResource1"></asp:LinkButton>
</EditItemTemplate>
</asp:TemplateColumn>

In the class file, here is the content of InitializeComponent() :
....
this.dgReceivedHistory.CancelCommand += new
System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgReceivedHistory_CancelCommand);
this.dgReceivedHistory.EditCommand += new
System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgReceivedHistory_EditCommand);
this.dgReceivedHistory.UpdateCommand += new
System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgReceivedHistory_UpdateCommand);

And the associated Edit function :
private void dgReceivedHistory_EditCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
....
dgReceivedHistory.EditItemIndex = e.Item.ItemIndex;
....
}

TIA.
 
O

Olivier Matrot

Steven,

I have found the problem modifying your sample to reach the same
functionnality in my project. My fault.

I'm using the event "ItemCreated" to set the focus to the first edit
control. This is done sending the corresponding javascript code with
Respone.Write().

This breaks the Postback generated code.
How can I automatically set the focus to the control with an alternate
method ?
TIA.
 
S

Steven Cheng[MSFT]

Hi Olivier,

Thanks for your response. Glad that you've made some progress. As for the
using Response.Write to output some client script for setting focus, would
you provide some further description on this or the complete code snippet
that can demonstrate the behavior you mentioned? BTW, in ASP.NET 2.0 , the
Page class has the "SetFocus" method which can accept a control instance or
clientID as paramter so that the page will register the proper client
script for us, does this function meet your requirement or there is any
further concerns in your case? Please feel free to let me know.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "Olivier Matrot" <[email protected]>
| References: <[email protected]>
<d#[email protected]>
<[email protected]>
| Subject: Re: ASP.NET 1.1 Converted Projet : Datagrid problem
| Date: Fri, 4 Nov 2005 11:12:09 +0100
| Lines: 154
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| X-RFC2646: Format=Flowed; Response
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| NNTP-Posting-Host: reverse.completel.net 213.30.138.178
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet.datagridcontrol:5916
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
|
| Steven,
|
| I have found the problem modifying your sample to reach the same
| functionnality in my project. My fault.
|
| I'm using the event "ItemCreated" to set the focus to the first edit
| control. This is done sending the corresponding javascript code with
| Respone.Write().
|
| This breaks the Postback generated code.
| How can I automatically set the focus to the control with an alternate
| method ?
| TIA.
|
| | > Hi Steven,
| >
| > After looking at your sample, here are my comments :
| > 1) I'm not using an AutogeneratedColumns datagrid.
| > 2) Bound columns are converted into templates to be customized.
| > 3) I'm not using the ItemCommand Event Handler.
| >
| > I 'll try to reproduce the problem with your page.
| > In the meantime, here are some additonnal informations :
| >
| > Here is the datagrid tag :
| > <asp:datagrid id="dgReceivedHistory" runat="server" Font-Names="Arial"
| > Font-Size="8pt" AllowSorting="True"
| > GridLines="None" AllowPaging="True"
AutoGenerateColumns="False"
| > CellPadding="5" BorderStyle="None" PageSize="15"
| > Height="10px" meta:resourcekey="dgReceivedHistoryResource1">
| >
| > Here is te converted datagrid template column :
| >
| > <asp:TemplateColumn SortExpression="Edit">
| > <HeaderStyle Wrap="False"></HeaderStyle>
| > <ItemStyle Wrap="False"></ItemStyle>
| > <ItemTemplate>
| > <asp:ImageButton id="ibModify" runat="server"
| > ImageUrl="img/modify.gif" CommandName="Edit" ToolTip="Modifier l'objet"
| > CausesValidation="False"
| > meta:resourcekey="ibModifyResource1"></asp:ImageButton>
| > </ItemTemplate>
| > <FooterStyle Wrap="False"></FooterStyle>
| > <EditItemTemplate>
| > <asp:LinkButton onkeypress="if((event.which &&
event.which
| > == 13) || (event.keyCode && event.keyCode == 13))
| > {ClickButton(event,'lbtnSubmit');return(false);}"
| > id="lbValidate" runat="server" Text="Valider"
| > CommandName="Update"
| > meta:resourcekey="lbValidateResource1"></asp:LinkButton>
| > <asp:LinkButton id="lbCancel" runat="server"
Text="Annuler"
| > CommandName="Cancel" CausesValidation="False"
| > meta:resourcekey="lbCancelResource1"></asp:LinkButton>
| > </EditItemTemplate>
| > </asp:TemplateColumn>
| >
| > In the class file, here is the content of InitializeComponent() :
| > ....
| > this.dgReceivedHistory.CancelCommand += new
| >
System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgReceivedHistory
_CancelCommand);
| > this.dgReceivedHistory.EditCommand += new
| >
System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgReceivedHistory
_EditCommand);
| > this.dgReceivedHistory.UpdateCommand += new
| >
System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgReceivedHistory
_UpdateCommand);
| >
| > And the associated Edit function :
| > private void dgReceivedHistory_EditCommand(object source,
| > System.Web.UI.WebControls.DataGridCommandEventArgs e)
| > {
| > ....
| > dgReceivedHistory.EditItemIndex = e.Item.ItemIndex;
| > ....
| > }
| >
| > TIA.
| >
| > | >> Hi Olivier,
| >>
| >> Welcome to ASPNET newsgroup.
| >> From your description you have upgrated an ASP.NET 1.X web application
to
| >> ASP.NET 2.0 through VS.NET 2005 's upgrate wizard. After that, one page
| >> which contains DataGrid control dosn't work correctly on the
| >> Update/Cancel
| >> command event ,yes?
| >>
| >> Based on my local test, I upgrade a simple DataGrid Page which use
| >> Autogenerate column and an edit column, after converting to asp.net
2.0,
| >> the Edit/Update/Cancel event still works as expected. So I'm thinking
| >> this
| >> is likely a page specific problem. If convenient, would you please
| >> provide
| >> me a simple reproduce page (asp.net 1.x version) so that I can try
| >> converting and test on my side? Also, I've attached my test page in
this
| >> message, you can also have a reference if you feel necessary).
| >>
| >> If there're anything else we can help, please feel free to post here.
| >>
| >> Regards,
| >>
| >> Steven Cheng
| >> Microsoft Online Support
| >>
| >> Get Secure! www.microsoft.com/security
| >> (This posting is provided "AS IS", with no warranties, and confers no
| >> rights.)
| >>
| >>
| >>
| >> --------------------
| >> | From: "Olivier Matrot" <[email protected]>
| >> | Subject: ASP.NET 1.1 Converted Projet : Datagrid problem
| >> | Date: Thu, 3 Nov 2005 17:10:18 +0100
| >> | Lines: 17
| >> | X-Priority: 3
| >> | X-MSMail-Priority: Normal
| >> | X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| >> | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| >> | X-RFC2646: Format=Flowed; Original
| >> | Message-ID: <[email protected]>
| >> | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| >> | NNTP-Posting-Host: reverse.completel.net 213.30.138.178
| >> | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
| >> | Xref: TK2MSFTNGXA01.phx.gbl
| >> microsoft.public.dotnet.framework.aspnet.datagridcontrol:5906
| >> | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| >> |
| >> | Hello,
| >> | I've converted an existing ASP.NET 1.1 project to Visual Studio 2005.
| >> | There is a problem with the Datagrid control. The Update & Cancel
| >> commands
| >> | are not working anymore (Edit is working).
| >> |
| >> | Ive noticed that the postback generated javascript has changed since
| >> | ASP.NET 1.1. For Example in ASP.NET 1.1, the Updade shortcut
| >> | is "javascript:__doPostBack('dgReceivedHistory$_ctl3$lbValidate','')"
| >> | In 2.0 it is now "javascript:__doPostBack('lbValidate','')".
| >> | The main differences is that there is no more reference to the
datagrid
| >> in
| >> | the client ID of the control...
| >> |
| >> | Any help apreciated.
| >> | TIA.
| >> |
| >> |
| >> |
| >> |
| >
| >
|
|
|
 
O

Olivier Matrot

Hi Steven,

Page.SetFocus is usefull.

1) I also need to select the text in the control. This was done by injecting
the following code :
StringBuilder js = new StringBuilder();
js.AppendFormat("<SCRIPT language='JavaScript'
event='onload'
for='window'>document.all('{0}').focus();document.all('{0}').select();</SCRIPT>",
subjectUpdated.ClientID);
Response.Write(js.ToString());

Again using this code breaks the Postback ! Is there something available
with ASP.NET 2.0 ?

2) Finally, I need to Set a default button (the update link) for the form
that is is created by the framework. This was done with the following code
and associated jscript :

textControl.Attributes.Add("onkeydown", "fnTrapKD('" +
defaultButton.UniqueID + "',event)");
thisPage.RegisterStartupScript("ForceDefaultToScriptImage",
defaultButtonScript);

------

defaultButtonScript = "<SCRIPT language=""javascript"">

<!--

function fnTrapKD(btnID, event){

btn = findObj(btnID);

if (document.all){

if (event.keyCode == 13){

event.returnValue=false;

event.cancel = true;

btn.click();

}

}

else if (document.getElementById){

if (event.which == 13){

event.returnValue=false;

event.cancel = true;

btn.focus();

btn.click();

}

}

else if(document.layers){

if(event.which == 13){

event.returnValue=false;

event.cancel = true;

btn.focus();

btn.click();

}

}

}

function findObj(n, d) {

var p,i,x;

if(!d)

d=document;

if((p=n.indexOf(""?""))>0 && parent.frames.length) {

d=parent.frames[n.substring(p+1)].document;

n=n.substring(0,p);

}

if(!(x=d[n])&&d.all)

x=d.all[n];

for (i=0;!x&&i<d.forms.length;i++)

x=d.forms[n];

for(i=0;!x&&d.layers&&i<d.layers.length;i++)

x=findObj(n,d.layers.document);

if(!x && d.getElementById)

x=d.getElementById(n);

return x;

}

// -->

</SCRIPT>"


I already know that there is a new property to to that for the form tag in
ASP.NET 2.0. Unfortunately, the form is generated by the framework when you
click the Edit button. Is it possible to access it from the ItemCreated
Event ?

TIA.
 
S

Steven Cheng[MSFT]

Thanks for your quick response Olivier,

Some comments regarding on your further description on your problem page:

1. We do not recommend use "Response.Write" to register script code or
script block in the page's response html content because "Response.Write"
directly write content into the response stream and is not rendered within
the html body ... so we can not gurantee it always work correctly.

2. For registering script which will be executed right after the page
render out at client, we suggest use Page.RegisterStartupScript, for
registering script block (helper script functions....), we suggest use
Page.RegisterClientScriptBlock function.

In 2.0, they're still available for backward compatiblilty, however, we
suggest you change them to the Page.ClientScript.XXX functions instead.

And as for your current problem page, I've built a new test page according
to your scenario. Instead of registering the script functions in
ItemCreated( I don't think that's the right place since the DataGridItem is
not added into parent control collection at that time...), I register the
script in ItemCommand after performing DataGrid.DataBind() ..... (Of
course I use the function mentioned above to register the script code....)

After converting the page in VS.NET 2005 to 2.0, I haven't met any problem,
it still works well. I've attached the new pages(1.0 and 2.0) in this
message. You can have a reference to see whether it helps. If there're
anything unclear, please feel free to let me know.

Thanks & Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "Olivier Matrot" <[email protected]>
| References: <[email protected]>
<d#[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
| Subject: Re: ASP.NET 1.1 Converted Projet : Datagrid problem
| Date: Fri, 4 Nov 2005 17:42:21 +0100
| Lines: 357
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| X-RFC2646: Format=Flowed; Original
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| NNTP-Posting-Host: reverse.completel.net 213.30.138.178
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet.datagridcontrol:5920
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
|
| Hi Steven,
|
| Page.SetFocus is usefull.
|
| 1) I also need to select the text in the control. This was done by
injecting
| the following code :
| StringBuilder js = new StringBuilder();
| js.AppendFormat("<SCRIPT language='JavaScript'
| event='onload'
|
for='window'>document.all('{0}').focus();document.all('{0}').select();</SCRI
PT>",
| subjectUpdated.ClientID);
| Response.Write(js.ToString());
|
| Again using this code breaks the Postback ! Is there something available
| with ASP.NET 2.0 ?
|
| 2) Finally, I need to Set a default button (the update link) for the form
| that is is created by the framework. This was done with the following
code
| and associated jscript :
|
| textControl.Attributes.Add("onkeydown", "fnTrapKD('" +
| defaultButton.UniqueID + "',event)");
| thisPage.RegisterStartupScript("ForceDefaultToScriptImage",
| defaultButtonScript);
|
| ------
|
| defaultButtonScript = "<SCRIPT language=""javascript"">
|
| <!--
|
| function fnTrapKD(btnID, event){
|
| btn = findObj(btnID);
|
| if (document.all){
|
| if (event.keyCode == 13){
|
| event.returnValue=false;
|
| event.cancel = true;
|
| btn.click();
|
| }
|
| }
|
| else if (document.getElementById){
|
| if (event.which == 13){
|
| event.returnValue=false;
|
| event.cancel = true;
|
| btn.focus();
|
| btn.click();
|
| }
|
| }
|
| else if(document.layers){
|
| if(event.which == 13){
|
| event.returnValue=false;
|
| event.cancel = true;
|
| btn.focus();
|
| btn.click();
|
| }
|
| }
|
| }
|
| function findObj(n, d) {
|
| var p,i,x;
|
| if(!d)
|
| d=document;
|
| if((p=n.indexOf(""?""))>0 && parent.frames.length) {
|
| d=parent.frames[n.substring(p+1)].document;
|
| n=n.substring(0,p);
|
| }
|
| if(!(x=d[n])&&d.all)
|
| x=d.all[n];
|
| for (i=0;!x&&i<d.forms.length;i++)
|
| x=d.forms[n];
|
| for(i=0;!x&&d.layers&&i<d.layers.length;i++)
|
| x=findObj(n,d.layers.document);
|
| if(!x && d.getElementById)
|
| x=d.getElementById(n);
|
| return x;
|
| }
|
| // -->
|
| </SCRIPT>"
|
|
| I already know that there is a new property to to that for the form tag
in
| ASP.NET 2.0. Unfortunately, the form is generated by the framework when
you
| click the Edit button. Is it possible to access it from the ItemCreated
| Event ?
|
| TIA.
|
|
| | > Hi Olivier,
| >
| > Thanks for your response. Glad that you've made some progress. As for
the
| > using Response.Write to output some client script for setting focus,
would
| > you provide some further description on this or the complete code
snippet
| > that can demonstrate the behavior you mentioned? BTW, in ASP.NET 2.0 ,
| > the
| > Page class has the "SetFocus" method which can accept a control
instance
| > or
| > clientID as paramter so that the page will register the proper client
| > script for us, does this function meet your requirement or there is any
| > further concerns in your case? Please feel free to let me know.
| >
| > Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| > --------------------
| > | From: "Olivier Matrot" <[email protected]>
| > | References: <[email protected]>
| > <d#[email protected]>
| > <[email protected]>
| > | Subject: Re: ASP.NET 1.1 Converted Projet : Datagrid problem
| > | Date: Fri, 4 Nov 2005 11:12:09 +0100
| > | Lines: 154
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| > | X-RFC2646: Format=Flowed; Response
| > | Message-ID: <[email protected]>
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > | NNTP-Posting-Host: reverse.completel.net 213.30.138.178
| > | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
| > | Xref: TK2MSFTNGXA01.phx.gbl
| > microsoft.public.dotnet.framework.aspnet.datagridcontrol:5916
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > |
| > | Steven,
| > |
| > | I have found the problem modifying your sample to reach the same
| > | functionnality in my project. My fault.
| > |
| > | I'm using the event "ItemCreated" to set the focus to the first edit
| > | control. This is done sending the corresponding javascript code with
| > | Respone.Write().
| > |
| > | This breaks the Postback generated code.
| > | How can I automatically set the focus to the control with an alternate
| > | method ?
| > | TIA.
| > |
| > | | > | > Hi Steven,
| > | >
| > | > After looking at your sample, here are my comments :
| > | > 1) I'm not using an AutogeneratedColumns datagrid.
| > | > 2) Bound columns are converted into templates to be customized.
| > | > 3) I'm not using the ItemCommand Event Handler.
| > | >
| > | > I 'll try to reproduce the problem with your page.
| > | > In the meantime, here are some additonnal informations :
| > | >
| > | > Here is the datagrid tag :
| > | > <asp:datagrid id="dgReceivedHistory" runat="server"
Font-Names="Arial"
| > | > Font-Size="8pt" AllowSorting="True"
| > | > GridLines="None" AllowPaging="True"
| > AutoGenerateColumns="False"
| > | > CellPadding="5" BorderStyle="None" PageSize="15"
| > | > Height="10px"
| > meta:resourcekey="dgReceivedHistoryResource1">
| > | >
| > | > Here is te converted datagrid template column :
| > | >
| > | > <asp:TemplateColumn SortExpression="Edit">
| > | > <HeaderStyle Wrap="False"></HeaderStyle>
| > | > <ItemStyle Wrap="False"></ItemStyle>
| > | > <ItemTemplate>
| > | > <asp:ImageButton id="ibModify" runat="server"
| > | > ImageUrl="img/modify.gif" CommandName="Edit" ToolTip="Modifier
| > l'objet"
| > | > CausesValidation="False"
| > | > meta:resourcekey="ibModifyResource1"></asp:ImageButton>
| > | > </ItemTemplate>
| > | > <FooterStyle Wrap="False"></FooterStyle>
| > | > <EditItemTemplate>
| > | > <asp:LinkButton onkeypress="if((event.which &&
| > event.which
| > | > == 13) || (event.keyCode && event.keyCode == 13))
| > | > {ClickButton(event,'lbtnSubmit');return(false);}"
| > | > id="lbValidate" runat="server" Text="Valider"
| > | > CommandName="Update"
| > | > meta:resourcekey="lbValidateResource1"></asp:LinkButton>
| > | > <asp:LinkButton id="lbCancel" runat="server"
| > Text="Annuler"
| > | > CommandName="Cancel" CausesValidation="False"
| > | > meta:resourcekey="lbCancelResource1"></asp:LinkButton>
| > | > </EditItemTemplate>
| > | > </asp:TemplateColumn>
| > | >
| > | > In the class file, here is the content of InitializeComponent() :
| > | > ....
| > | > this.dgReceivedHistory.CancelCommand += new
| > | >
| >
System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgReceivedHistory
| > _CancelCommand);
| > | > this.dgReceivedHistory.EditCommand += new
| > | >
| >
System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgReceivedHistory
| > _EditCommand);
| > | > this.dgReceivedHistory.UpdateCommand += new
| > | >
| >
System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgReceivedHistory
| > _UpdateCommand);
| > | >
| > | > And the associated Edit function :
| > | > private void dgReceivedHistory_EditCommand(object source,
| > | > System.Web.UI.WebControls.DataGridCommandEventArgs e)
| > | > {
| > | > ....
| > | > dgReceivedHistory.EditItemIndex = e.Item.ItemIndex;
| > | > ....
| > | > }
| > | >
| > | > TIA.
| > | >
| > | > | > | >> Hi Olivier,
| > | >>
| > | >> Welcome to ASPNET newsgroup.
| > | >> From your description you have upgrated an ASP.NET 1.X web
| > application
| > to
| > | >> ASP.NET 2.0 through VS.NET 2005 's upgrate wizard. After that, one
| > page
| > | >> which contains DataGrid control dosn't work correctly on the
| > | >> Update/Cancel
| > | >> command event ,yes?
| > | >>
| > | >> Based on my local test, I upgrade a simple DataGrid Page which use
| > | >> Autogenerate column and an edit column, after converting to asp.net
| > 2.0,
| > | >> the Edit/Update/Cancel event still works as expected. So I'm
thinking
| > | >> this
| > | >> is likely a page specific problem. If convenient, would you please
| > | >> provide
| > | >> me a simple reproduce page (asp.net 1.x version) so that I can try
| > | >> converting and test on my side? Also, I've attached my test page in
| > this
| > | >> message, you can also have a reference if you feel necessary).
| > | >>
| > | >> If there're anything else we can help, please feel free to post
here.
| > | >>
| > | >> Regards,
| > | >>
| > | >> Steven Cheng
| > | >> Microsoft Online Support
| > | >>
| > | >> Get Secure! www.microsoft.com/security
| > | >> (This posting is provided "AS IS", with no warranties, and confers
no
| > | >> rights.)
| > | >>
| > | >>
| > | >>
| > | >> --------------------
| > | >> | From: "Olivier Matrot" <[email protected]>
| > | >> | Subject: ASP.NET 1.1 Converted Projet : Datagrid problem
| > | >> | Date: Thu, 3 Nov 2005 17:10:18 +0100
| > | >> | Lines: 17
| > | >> | X-Priority: 3
| > | >> | X-MSMail-Priority: Normal
| > | >> | X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| > | >> | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| > | >> | X-RFC2646: Format=Flowed; Original
| > | >> | Message-ID: <[email protected]>
| > | >> | Newsgroups:
| > microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > | >> | NNTP-Posting-Host: reverse.completel.net 213.30.138.178
| > | >> | Path:
| > TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
| > | >> | Xref: TK2MSFTNGXA01.phx.gbl
| > | >> microsoft.public.dotnet.framework.aspnet.datagridcontrol:5906
| > | >> | X-Tomcat-NG:
| > microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > | >> |
| > | >> | Hello,
| > | >> | I've converted an existing ASP.NET 1.1 project to Visual Studio
| > 2005.
| > | >> | There is a problem with the Datagrid control. The Update & Cancel
| > | >> commands
| > | >> | are not working anymore (Edit is working).
| > | >> |
| > | >> | Ive noticed that the postback generated javascript has changed
| > since
| > | >> | ASP.NET 1.1. For Example in ASP.NET 1.1, the Updade shortcut
| > | >> | is
| > "javascript:__doPostBack('dgReceivedHistory$_ctl3$lbValidate','')"
| > | >> | In 2.0 it is now "javascript:__doPostBack('lbValidate','')".
| > | >> | The main differences is that there is no more reference to the
| > datagrid
| > | >> in
| > | >> | the client ID of the control...
| > | >> |
| > | >> | Any help apreciated.
| > | >> | TIA.
| > | >> |
| > | >> |
| > | >> |
| > | >> |
| > | >
| >| >
| > |
| > |
| > |
| >
|
|
|
 
O

Olivier Matrot

Hi Steven,

Thanks for your answers.
I'm using you functionr "RegisterScriptForEditItem" in the ItemDataBound
Event Handler and it is working fine.

Thanks !

Steven Cheng said:
Thanks for your quick response Olivier,

Some comments regarding on your further description on your problem page:

1. We do not recommend use "Response.Write" to register script code or
script block in the page's response html content because "Response.Write"
directly write content into the response stream and is not rendered within
the html body ... so we can not gurantee it always work correctly.

2. For registering script which will be executed right after the page
render out at client, we suggest use Page.RegisterStartupScript, for
registering script block (helper script functions....), we suggest use
Page.RegisterClientScriptBlock function.

In 2.0, they're still available for backward compatiblilty, however, we
suggest you change them to the Page.ClientScript.XXX functions instead.

And as for your current problem page, I've built a new test page according
to your scenario. Instead of registering the script functions in
ItemCreated( I don't think that's the right place since the DataGridItem
is
not added into parent control collection at that time...), I register the
script in ItemCommand after performing DataGrid.DataBind() ..... (Of
course I use the function mentioned above to register the script
code....)

After converting the page in VS.NET 2005 to 2.0, I haven't met any
problem,
it still works well. I've attached the new pages(1.0 and 2.0) in this
message. You can have a reference to see whether it helps. If there're
anything unclear, please feel free to let me know.

Thanks & Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "Olivier Matrot" <[email protected]>
| References: <[email protected]>
<d#[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
| Subject: Re: ASP.NET 1.1 Converted Projet : Datagrid problem
| Date: Fri, 4 Nov 2005 17:42:21 +0100
| Lines: 357
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| X-RFC2646: Format=Flowed; Original
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| NNTP-Posting-Host: reverse.completel.net 213.30.138.178
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet.datagridcontrol:5920
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
|
| Hi Steven,
|
| Page.SetFocus is usefull.
|
| 1) I also need to select the text in the control. This was done by
injecting
| the following code :
| StringBuilder js = new StringBuilder();
| js.AppendFormat("<SCRIPT language='JavaScript'
| event='onload'
|
for='window'>document.all('{0}').focus();document.all('{0}').select();</SCRI
PT>",
| subjectUpdated.ClientID);
| Response.Write(js.ToString());
|
| Again using this code breaks the Postback ! Is there something available
| with ASP.NET 2.0 ?
|
| 2) Finally, I need to Set a default button (the update link) for the
form
| that is is created by the framework. This was done with the following
code
| and associated jscript :
|
| textControl.Attributes.Add("onkeydown", "fnTrapKD('" +
| defaultButton.UniqueID + "',event)");
| thisPage.RegisterStartupScript("ForceDefaultToScriptImage",
| defaultButtonScript);
|
| ------
|
| defaultButtonScript = "<SCRIPT language=""javascript"">
|
| <!--
|
| function fnTrapKD(btnID, event){
|
| btn = findObj(btnID);
|
| if (document.all){
|
| if (event.keyCode == 13){
|
| event.returnValue=false;
|
| event.cancel = true;
|
| btn.click();
|
| }
|
| }
|
| else if (document.getElementById){
|
| if (event.which == 13){
|
| event.returnValue=false;
|
| event.cancel = true;
|
| btn.focus();
|
| btn.click();
|
| }
|
| }
|
| else if(document.layers){
|
| if(event.which == 13){
|
| event.returnValue=false;
|
| event.cancel = true;
|
| btn.focus();
|
| btn.click();
|
| }
|
| }
|
| }
|
| function findObj(n, d) {
|
| var p,i,x;
|
| if(!d)
|
| d=document;
|
| if((p=n.indexOf(""?""))>0 && parent.frames.length) {
|
| d=parent.frames[n.substring(p+1)].document;
|
| n=n.substring(0,p);
|
| }
|
| if(!(x=d[n])&&d.all)
|
| x=d.all[n];
|
| for (i=0;!x&&i<d.forms.length;i++)
|
| x=d.forms[n];
|
| for(i=0;!x&&d.layers&&i<d.layers.length;i++)
|
| x=findObj(n,d.layers.document);
|
| if(!x && d.getElementById)
|
| x=d.getElementById(n);
|
| return x;
|
| }
|
| // -->
|
| </SCRIPT>"
|
|
| I already know that there is a new property to to that for the form tag
in
| ASP.NET 2.0. Unfortunately, the form is generated by the framework when
you
| click the Edit button. Is it possible to access it from the ItemCreated
| Event ?
|
| TIA.
|
|
| | > Hi Olivier,
| >
| > Thanks for your response. Glad that you've made some progress. As for
the
| > using Response.Write to output some client script for setting focus,
would
| > you provide some further description on this or the complete code
snippet
| > that can demonstrate the behavior you mentioned? BTW, in ASP.NET 2.0
,
| > the
| > Page class has the "SetFocus" method which can accept a control
instance
| > or
| > clientID as paramter so that the page will register the proper client
| > script for us, does this function meet your requirement or there is
any
| > further concerns in your case? Please feel free to let me know.
| >
| > Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| > --------------------
| > | From: "Olivier Matrot" <[email protected]>
| > | References: <[email protected]>
| > <d#[email protected]>
| > <[email protected]>
| > | Subject: Re: ASP.NET 1.1 Converted Projet : Datagrid problem
| > | Date: Fri, 4 Nov 2005 11:12:09 +0100
| > | Lines: 154
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| > | X-RFC2646: Format=Flowed; Response
| > | Message-ID: <[email protected]>
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > | NNTP-Posting-Host: reverse.completel.net 213.30.138.178
| > | Path:
TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
| > | Xref: TK2MSFTNGXA01.phx.gbl
| > microsoft.public.dotnet.framework.aspnet.datagridcontrol:5916
| > | X-Tomcat-NG:
microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > |
| > | Steven,
| > |
| > | I have found the problem modifying your sample to reach the same
| > | functionnality in my project. My fault.
| > |
| > | I'm using the event "ItemCreated" to set the focus to the first edit
| > | control. This is done sending the corresponding javascript code with
| > | Respone.Write().
| > |
| > | This breaks the Postback generated code.
| > | How can I automatically set the focus to the control with an
alternate
| > | method ?
| > | TIA.
| > |
| > | | > | > Hi Steven,
| > | >
| > | > After looking at your sample, here are my comments :
| > | > 1) I'm not using an AutogeneratedColumns datagrid.
| > | > 2) Bound columns are converted into templates to be customized.
| > | > 3) I'm not using the ItemCommand Event Handler.
| > | >
| > | > I 'll try to reproduce the problem with your page.
| > | > In the meantime, here are some additonnal informations :
| > | >
| > | > Here is the datagrid tag :
| > | > <asp:datagrid id="dgReceivedHistory" runat="server"
Font-Names="Arial"
| > | > Font-Size="8pt" AllowSorting="True"
| > | > GridLines="None" AllowPaging="True"
| > AutoGenerateColumns="False"
| > | > CellPadding="5" BorderStyle="None" PageSize="15"
| > | > Height="10px"
| > meta:resourcekey="dgReceivedHistoryResource1">
| > | >
| > | > Here is te converted datagrid template column :
| > | >
| > | > <asp:TemplateColumn SortExpression="Edit">
| > | > <HeaderStyle Wrap="False"></HeaderStyle>
| > | > <ItemStyle Wrap="False"></ItemStyle>
| > | > <ItemTemplate>
| > | > <asp:ImageButton id="ibModify" runat="server"
| > | > ImageUrl="img/modify.gif" CommandName="Edit" ToolTip="Modifier
| > l'objet"
| > | > CausesValidation="False"
| > | > meta:resourcekey="ibModifyResource1"></asp:ImageButton>
| > | > </ItemTemplate>
| > | > <FooterStyle Wrap="False"></FooterStyle>
| > | > <EditItemTemplate>
| > | > <asp:LinkButton onkeypress="if((event.which &&
| > event.which
| > | > == 13) || (event.keyCode && event.keyCode == 13))
| > | > {ClickButton(event,'lbtnSubmit');return(false);}"
| > | > id="lbValidate" runat="server" Text="Valider"
| > | > CommandName="Update"
| > | > meta:resourcekey="lbValidateResource1"></asp:LinkButton>
| > | > <asp:LinkButton id="lbCancel" runat="server"
| > Text="Annuler"
| > | > CommandName="Cancel" CausesValidation="False"
| > | > meta:resourcekey="lbCancelResource1"></asp:LinkButton>
| > | > </EditItemTemplate>
| > | > </asp:TemplateColumn>
| > | >
| > | > In the class file, here is the content of InitializeComponent() :
| > | > ....
| > | > this.dgReceivedHistory.CancelCommand += new
| > | >
| >
System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgReceivedHistory
| > _CancelCommand);
| > | > this.dgReceivedHistory.EditCommand += new
| > | >
| >
System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgReceivedHistory
| > _EditCommand);
| > | > this.dgReceivedHistory.UpdateCommand += new
| > | >
| >
System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgReceivedHistory
| > _UpdateCommand);
| > | >
| > | > And the associated Edit function :
| > | > private void dgReceivedHistory_EditCommand(object source,
| > | > System.Web.UI.WebControls.DataGridCommandEventArgs e)
| > | > {
| > | > ....
| > | > dgReceivedHistory.EditItemIndex = e.Item.ItemIndex;
| > | > ....
| > | > }
| > | >
| > | > TIA.
| > | >
message
| > | > | > | >> Hi Olivier,
| > | >>
| > | >> Welcome to ASPNET newsgroup.
| > | >> From your description you have upgrated an ASP.NET 1.X web
| > application
| > to
| > | >> ASP.NET 2.0 through VS.NET 2005 's upgrate wizard. After that,
one
| > page
| > | >> which contains DataGrid control dosn't work correctly on the
| > | >> Update/Cancel
| > | >> command event ,yes?
| > | >>
| > | >> Based on my local test, I upgrade a simple DataGrid Page which
use
| > | >> Autogenerate column and an edit column, after converting to
asp.net
| > 2.0,
| > | >> the Edit/Update/Cancel event still works as expected. So I'm
thinking
| > | >> this
| > | >> is likely a page specific problem. If convenient, would you
please
| > | >> provide
| > | >> me a simple reproduce page (asp.net 1.x version) so that I can
try
| > | >> converting and test on my side? Also, I've attached my test page
in
| > this
| > | >> message, you can also have a reference if you feel necessary).
| > | >>
| > | >> If there're anything else we can help, please feel free to post
here.
| > | >>
| > | >> Regards,
| > | >>
| > | >> Steven Cheng
| > | >> Microsoft Online Support
| > | >>
| > | >> Get Secure! www.microsoft.com/security
| > | >> (This posting is provided "AS IS", with no warranties, and
confers
no
| > | >> rights.)
| > | >>
| > | >>
| > | >>
| > | >> --------------------
| > | >> | From: "Olivier Matrot" <[email protected]>
| > | >> | Subject: ASP.NET 1.1 Converted Projet : Datagrid problem
| > | >> | Date: Thu, 3 Nov 2005 17:10:18 +0100
| > | >> | Lines: 17
| > | >> | X-Priority: 3
| > | >> | X-MSMail-Priority: Normal
| > | >> | X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| > | >> | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| > | >> | X-RFC2646: Format=Flowed; Original
| > | >> | Message-ID: <[email protected]>
| > | >> | Newsgroups:
| > microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > | >> | NNTP-Posting-Host: reverse.completel.net 213.30.138.178
| > | >> | Path:
| > TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
| > | >> | Xref: TK2MSFTNGXA01.phx.gbl
| > | >> microsoft.public.dotnet.framework.aspnet.datagridcontrol:5906
| > | >> | X-Tomcat-NG:
| > microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > | >> |
| > | >> | Hello,
| > | >> | I've converted an existing ASP.NET 1.1 project to Visual Studio
| > 2005.
| > | >> | There is a problem with the Datagrid control. The Update &
Cancel
| > | >> commands
| > | >> | are not working anymore (Edit is working).
| > | >> |
| > | >> | Ive noticed that the postback generated javascript has changed
| > since
| > | >> | ASP.NET 1.1. For Example in ASP.NET 1.1, the Updade shortcut
| > | >> | is
| > "javascript:__doPostBack('dgReceivedHistory$_ctl3$lbValidate','')"
| > | >> | In 2.0 it is now "javascript:__doPostBack('lbValidate','')".
| > | >> | The main differences is that there is no more reference to the
| > datagrid
| > | >> in
| > | >> | the client ID of the control...
| > | >> |
| > | >> | Any help apreciated.
| > | >> | TIA.
| > | >> |
| > | >> |
| > | >> |
| > | >> |
| > | >
| >| >
| > |
| > |
| > |
| >
|
|
|
 
S

Steven Cheng[MSFT]

Good news Olivier,

It's my pleasure help you work on this.

Enjoy ASP.NET 2.0.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "Olivier Matrot" <[email protected]>
| References: <[email protected]>
<d#[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
| Subject: Re: ASP.NET 1.1 Converted Projet : Datagrid problem
| Date: Mon, 7 Nov 2005 09:10:22 +0100
| Lines: 465
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| X-RFC2646: Format=Flowed; Original
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| NNTP-Posting-Host: reverse.completel.net 213.30.138.178
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP15.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet.datagridcontrol:5943
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
|
| Hi Steven,
|
| Thanks for your answers.
| I'm using you functionr "RegisterScriptForEditItem" in the ItemDataBound
| Event Handler and it is working fine.
|
| Thanks !
|
| | > Thanks for your quick response Olivier,
| >
| > Some comments regarding on your further description on your problem
page:
| >
| > 1. We do not recommend use "Response.Write" to register script code or
| > script block in the page's response html content because
"Response.Write"
| > directly write content into the response stream and is not rendered
within
| > the html body ... so we can not gurantee it always work correctly.
| >
| > 2. For registering script which will be executed right after the page
| > render out at client, we suggest use Page.RegisterStartupScript, for
| > registering script block (helper script functions....), we suggest use
| > Page.RegisterClientScriptBlock function.
| >
| > In 2.0, they're still available for backward compatiblilty, however, we
| > suggest you change them to the Page.ClientScript.XXX functions instead.
| >
| > And as for your current problem page, I've built a new test page
according
| > to your scenario. Instead of registering the script functions in
| > ItemCreated( I don't think that's the right place since the
DataGridItem
| > is
| > not added into parent control collection at that time...), I register
the
| > script in ItemCommand after performing DataGrid.DataBind() ..... (Of
| > course I use the function mentioned above to register the script
| > code....)
| >
| > After converting the page in VS.NET 2005 to 2.0, I haven't met any
| > problem,
| > it still works well. I've attached the new pages(1.0 and 2.0) in this
| > message. You can have a reference to see whether it helps. If there're
| > anything unclear, please feel free to let me know.
| >
| > Thanks & Regards,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| > --------------------
| > | From: "Olivier Matrot" <[email protected]>
| > | References: <[email protected]>
| > <d#[email protected]>
| > <[email protected]>
| > <[email protected]>
| > <[email protected]>
| > | Subject: Re: ASP.NET 1.1 Converted Projet : Datagrid problem
| > | Date: Fri, 4 Nov 2005 17:42:21 +0100
| > | Lines: 357
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| > | X-RFC2646: Format=Flowed; Original
| > | Message-ID: <[email protected]>
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > | NNTP-Posting-Host: reverse.completel.net 213.30.138.178
| > | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
| > | Xref: TK2MSFTNGXA01.phx.gbl
| > microsoft.public.dotnet.framework.aspnet.datagridcontrol:5920
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > |
| > | Hi Steven,
| > |
| > | Page.SetFocus is usefull.
| > |
| > | 1) I also need to select the text in the control. This was done by
| > injecting
| > | the following code :
| > | StringBuilder js = new StringBuilder();
| > | js.AppendFormat("<SCRIPT language='JavaScript'
| > | event='onload'
| > |
| >
for='window'>document.all('{0}').focus();document.all('{0}').select();</SCRI
| > PT>",
| > | subjectUpdated.ClientID);
| > | Response.Write(js.ToString());
| > |
| > | Again using this code breaks the Postback ! Is there something
available
| > | with ASP.NET 2.0 ?
| > |
| > | 2) Finally, I need to Set a default button (the update link) for the
| > form
| > | that is is created by the framework. This was done with the following
| > code
| > | and associated jscript :
| > |
| > | textControl.Attributes.Add("onkeydown", "fnTrapKD('" +
| > | defaultButton.UniqueID + "',event)");
| > | thisPage.RegisterStartupScript("ForceDefaultToScriptImage",
| > | defaultButtonScript);
| > |
| > | ------
| > |
| > | defaultButtonScript = "<SCRIPT language=""javascript"">
| > |
| > | <!--
| > |
| > | function fnTrapKD(btnID, event){
| > |
| > | btn = findObj(btnID);
| > |
| > | if (document.all){
| > |
| > | if (event.keyCode == 13){
| > |
| > | event.returnValue=false;
| > |
| > | event.cancel = true;
| > |
| > | btn.click();
| > |
| > | }
| > |
| > | }
| > |
| > | else if (document.getElementById){
| > |
| > | if (event.which == 13){
| > |
| > | event.returnValue=false;
| > |
| > | event.cancel = true;
| > |
| > | btn.focus();
| > |
| > | btn.click();
| > |
| > | }
| > |
| > | }
| > |
| > | else if(document.layers){
| > |
| > | if(event.which == 13){
| > |
| > | event.returnValue=false;
| > |
| > | event.cancel = true;
| > |
| > | btn.focus();
| > |
| > | btn.click();
| > |
| > | }
| > |
| > | }
| > |
| > | }
| > |
| > | function findObj(n, d) {
| > |
| > | var p,i,x;
| > |
| > | if(!d)
| > |
| > | d=document;
| > |
| > | if((p=n.indexOf(""?""))>0 && parent.frames.length) {
| > |
| > | d=parent.frames[n.substring(p+1)].document;
| > |
| > | n=n.substring(0,p);
| > |
| > | }
| > |
| > | if(!(x=d[n])&&d.all)
| > |
| > | x=d.all[n];
| > |
| > | for (i=0;!x&&i<d.forms.length;i++)
| > |
| > | x=d.forms[n];
| > |
| > | for(i=0;!x&&d.layers&&i<d.layers.length;i++)
| > |
| > | x=findObj(n,d.layers.document);
| > |
| > | if(!x && d.getElementById)
| > |
| > | x=d.getElementById(n);
| > |
| > | return x;
| > |
| > | }
| > |
| > | // -->
| > |
| > | </SCRIPT>"
| > |
| > |
| > | I already know that there is a new property to to that for the form
tag
| > in
| > | ASP.NET 2.0. Unfortunately, the form is generated by the framework
when
| > you
| > | click the Edit button. Is it possible to access it from the
ItemCreated
| > | Event ?
| > |
| > | TIA.
| > |
| > |
| > | | > | > Hi Olivier,
| > | >
| > | > Thanks for your response. Glad that you've made some progress. As
for
| > the
| > | > using Response.Write to output some client script for setting focus,
| > would
| > | > you provide some further description on this or the complete code
| > snippet
| > | > that can demonstrate the behavior you mentioned? BTW, in ASP.NET
2.0
| > ,
| > | > the
| > | > Page class has the "SetFocus" method which can accept a control
| > instance
| > | > or
| > | > clientID as paramter so that the page will register the proper
client
| > | > script for us, does this function meet your requirement or there is
| > any
| > | > further concerns in your case? Please feel free to let me know.
| > | >
| > | > Thanks,
| > | >
| > | > Steven Cheng
| > | > Microsoft Online Support
| > | >
| > | > Get Secure! www.microsoft.com/security
| > | > (This posting is provided "AS IS", with no warranties, and confers
no
| > | > rights.)
| > | > --------------------
| > | > | From: "Olivier Matrot" <[email protected]>
| > | > | References: <[email protected]>
| > | > <d#[email protected]>
| > | > <[email protected]>
| > | > | Subject: Re: ASP.NET 1.1 Converted Projet : Datagrid problem
| > | > | Date: Fri, 4 Nov 2005 11:12:09 +0100
| > | > | Lines: 154
| > | > | X-Priority: 3
| > | > | X-MSMail-Priority: Normal
| > | > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| > | > | X-RFC2646: Format=Flowed; Response
| > | > | Message-ID: <[email protected]>
| > | > | Newsgroups:
microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > | > | NNTP-Posting-Host: reverse.completel.net 213.30.138.178
| > | > | Path:
| > TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
| > | > | Xref: TK2MSFTNGXA01.phx.gbl
| > | > microsoft.public.dotnet.framework.aspnet.datagridcontrol:5916
| > | > | X-Tomcat-NG:
| > microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > | > |
| > | > | Steven,
| > | > |
| > | > | I have found the problem modifying your sample to reach the same
| > | > | functionnality in my project. My fault.
| > | > |
| > | > | I'm using the event "ItemCreated" to set the focus to the first
edit
| > | > | control. This is done sending the corresponding javascript code
with
| > | > | Respone.Write().
| > | > |
| > | > | This breaks the Postback generated code.
| > | > | How can I automatically set the focus to the control with an
| > alternate
| > | > | method ?
| > | > | TIA.
| > | > |
message
| > | > | | > | > | > Hi Steven,
| > | > | >
| > | > | > After looking at your sample, here are my comments :
| > | > | > 1) I'm not using an AutogeneratedColumns datagrid.
| > | > | > 2) Bound columns are converted into templates to be customized.
| > | > | > 3) I'm not using the ItemCommand Event Handler.
| > | > | >
| > | > | > I 'll try to reproduce the problem with your page.
| > | > | > In the meantime, here are some additonnal informations :
| > | > | >
| > | > | > Here is the datagrid tag :
| > | > | > <asp:datagrid id="dgReceivedHistory" runat="server"
| > Font-Names="Arial"
| > | > | > Font-Size="8pt" AllowSorting="True"
| > | > | > GridLines="None" AllowPaging="True"
| > | > AutoGenerateColumns="False"
| > | > | > CellPadding="5" BorderStyle="None" PageSize="15"
| > | > | > Height="10px"
| > | > meta:resourcekey="dgReceivedHistoryResource1">
| > | > | >
| > | > | > Here is te converted datagrid template column :
| > | > | >
| > | > | > <asp:TemplateColumn SortExpression="Edit">
| > | > | > <HeaderStyle Wrap="False"></HeaderStyle>
| > | > | > <ItemStyle Wrap="False"></ItemStyle>
| > | > | > <ItemTemplate>
| > | > | > <asp:ImageButton id="ibModify" runat="server"
| > | > | > ImageUrl="img/modify.gif" CommandName="Edit" ToolTip="Modifier
| > | > l'objet"
| > | > | > CausesValidation="False"
| > | > | > meta:resourcekey="ibModifyResource1"></asp:ImageButton>
| > | > | > </ItemTemplate>
| > | > | > <FooterStyle Wrap="False"></FooterStyle>
| > | > | > <EditItemTemplate>
| > | > | > <asp:LinkButton onkeypress="if((event.which &&
| > | > event.which
| > | > | > == 13) || (event.keyCode && event.keyCode == 13))
| > | > | > {ClickButton(event,'lbtnSubmit');return(false);}"
| > | > | > id="lbValidate" runat="server" Text="Valider"
| > | > | > CommandName="Update"
| > | > | > meta:resourcekey="lbValidateResource1"></asp:LinkButton>
| > | > | > <asp:LinkButton id="lbCancel" runat="server"
| > | > Text="Annuler"
| > | > | > CommandName="Cancel" CausesValidation="False"
| > | > | > meta:resourcekey="lbCancelResource1"></asp:LinkButton>
| > | > | > </EditItemTemplate>
| > | > | > </asp:TemplateColumn>
| > | > | >
| > | > | > In the class file, here is the content of InitializeComponent()
:
| > | > | > ....
| > | > | > this.dgReceivedHistory.CancelCommand += new
| > | > | >
| > | >
| >
System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgReceivedHistory
| > | > _CancelCommand);
| > | > | > this.dgReceivedHistory.EditCommand += new
| > | > | >
| > | >
| >
System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgReceivedHistory
| > | > _EditCommand);
| > | > | > this.dgReceivedHistory.UpdateCommand += new
| > | > | >
| > | >
| >
System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgReceivedHistory
| > | > _UpdateCommand);
| > | > | >
| > | > | > And the associated Edit function :
| > | > | > private void dgReceivedHistory_EditCommand(object source,
| > | > | > System.Web.UI.WebControls.DataGridCommandEventArgs e)
| > | > | > {
| > | > | > ....
| > | > | > dgReceivedHistory.EditItemIndex = e.Item.ItemIndex;
| > | > | > ....
| > | > | > }
| > | > | >
| > | > | > TIA.
| > | > | >
| > message
| > | > | > | > | > | >> Hi Olivier,
| > | > | >>
| > | > | >> Welcome to ASPNET newsgroup.
| > | > | >> From your description you have upgrated an ASP.NET 1.X web
| > | > application
| > | > to
| > | > | >> ASP.NET 2.0 through VS.NET 2005 's upgrate wizard. After that,
| > one
| > | > page
| > | > | >> which contains DataGrid control dosn't work correctly on the
| > | > | >> Update/Cancel
| > | > | >> command event ,yes?
| > | > | >>
| > | > | >> Based on my local test, I upgrade a simple DataGrid Page which
| > use
| > | > | >> Autogenerate column and an edit column, after converting to
| > asp.net
| > | > 2.0,
| > | > | >> the Edit/Update/Cancel event still works as expected. So I'm
| > thinking
| > | > | >> this
| > | > | >> is likely a page specific problem. If convenient, would you
| > please
| > | > | >> provide
| > | > | >> me a simple reproduce page (asp.net 1.x version) so that I can
| > try
| > | > | >> converting and test on my side? Also, I've attached my test
page
| > in
| > | > this
| > | > | >> message, you can also have a reference if you feel necessary).
| > | > | >>
| > | > | >> If there're anything else we can help, please feel free to post
| > here.
| > | > | >>
| > | > | >> Regards,
| > | > | >>
| > | > | >> Steven Cheng
| > | > | >> Microsoft Online Support
| > | > | >>
| > | > | >> Get Secure! www.microsoft.com/security
| > | > | >> (This posting is provided "AS IS", with no warranties, and
| > confers
| > no
| > | > | >> rights.)
| > | > | >>
| > | > | >>
| > | > | >>
| > | > | >> --------------------
| > | > | >> | From: "Olivier Matrot" <[email protected]>
| > | > | >> | Subject: ASP.NET 1.1 Converted Projet : Datagrid problem
| > | > | >> | Date: Thu, 3 Nov 2005 17:10:18 +0100
| > | > | >> | Lines: 17
| > | > | >> | X-Priority: 3
| > | > | >> | X-MSMail-Priority: Normal
| > | > | >> | X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| > | > | >> | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| > | > | >> | X-RFC2646: Format=Flowed; Original
| > | > | >> | Message-ID: <[email protected]>
| > | > | >> | Newsgroups:
| > | > microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > | > | >> | NNTP-Posting-Host: reverse.completel.net 213.30.138.178
| > | > | >> | Path:
| > | > TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
| > | > | >> | Xref: TK2MSFTNGXA01.phx.gbl
| > | > | >> microsoft.public.dotnet.framework.aspnet.datagridcontrol:5906
| > | > | >> | X-Tomcat-NG:
| > | > microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > | > | >> |
| > | > | >> | Hello,
| > | > | >> | I've converted an existing ASP.NET 1.1 project to Visual
Studio
| > | > 2005.
| > | > | >> | There is a problem with the Datagrid control. The Update &
| > Cancel
| > | > | >> commands
| > | > | >> | are not working anymore (Edit is working).
| > | > | >> |
| > | > | >> | Ive noticed that the postback generated javascript has
changed
| > | > since
| > | > | >> | ASP.NET 1.1. For Example in ASP.NET 1.1, the Updade shortcut
| > | > | >> | is
| > | > "javascript:__doPostBack('dgReceivedHistory$_ctl3$lbValidate','')"
| > | > | >> | In 2.0 it is now "javascript:__doPostBack('lbValidate','')".
| > | > | >> | The main differences is that there is no more reference to
the
| > | > datagrid
| > | > | >> in
| > | > | >> | the client ID of the control...
| > | > | >> |
| > | > | >> | Any help apreciated.
| > | > | >> | TIA.
| > | > | >> |
| > | > | >> |
| > | > | >> |
| > | > | >> |
| > | > | >
| > | >| >
| > | > |
| > | > |
| > | > |
| > | >
| > |
| > |
| > |
|
|
|
 

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,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top