ASP.NET 1.1 Converted Projet : Datagrid problem

Ask a Question related to ASP.NET Data Grid Control, Design and Development.

  1. #1

    Default ASP.NET 1.1 Converted Projet : Datagrid problem

    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.



    Olivier Matrot Guest

  2. Similar Questions and Discussions

    1. Overprint Not Converted to PDF Correctly
      I inadvertently checked the "Overprint Fill" setting in Illustrator CS2 for a placed bitmap object which was set to a white fill. I saved the...
    2. Value can not be converted to requested type.
      Having a peculiar problem running a MS-SQL 2000 Stored Procedure in CFMX6.1. SP works perfectly in Query Analyzer and has the right permissions for...
    3. problema ultima pagina datagrid asp.net/problem last page datagrid
      ciao, ho un problema. ho un datagrid in una pagina asp.net con le impostazioni di PAGING abilitate. Uso l'impostazione NUMERIC PAGE. Il problema è...
    4. why is . converted to _ in $_POST
      I have a form that contains some file names (eg this.jpg). When the form posts, and i ready $_POST, I get back this_jpg. What is happening? how...
    5. web form newlines converted to <BR>
      I wish to use a perl cgi script to convert the new line characters from a text area in a web form into the HTML <BR> tag. I am a novice so just the...
  3. #2

    Default Re: ASP.NET 1.1 Converted Projet : Datagrid problem

    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.DataGridCommandEventHand ler(this.dgReceivedHistory_CancelCommand);
    this.dgReceivedHistory.EditCommand += new
    System.Web.UI.WebControls.DataGridCommandEventHand ler(this.dgReceivedHistory_EditCommand);
    this.dgReceivedHistory.UpdateCommand += new
    System.Web.UI.WebControls.DataGridCommandEventHand ler(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.

    "Steven Cheng[MSFT]" <stcheng@online.microsoft.com> wrote in message
    news:d%234HKPP4FHA.3220@TK2MSFTNGXA01.phx.gbl...
    > 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! [url]www.microsoft.com/security[/url]
    > (This posting is provided "AS IS", with no warranties, and confers no
    > rights.)
    >
    >
    >
    > --------------------
    > | From: "Olivier Matrot" <olivier.matrot.rte@online.nospam>
    > | 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: <OBAmWEJ4FHA.3876@TK2MSFTNGP09.phx.gbl>
    > | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    > | NNTP-Posting-Host: reverse.completel.net 213.30.138.178
    > | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP09.phx.gbl
    > | Xref: TK2MSFTNGXA01.phx.gbl
    > microsoft.public.dotnet.framework.aspnet.datagridc ontrol:5906
    > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    > |
    > | 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.
    > |
    > |
    > |
    > |

    Olivier Matrot Guest

  4. #3

    Default Re: ASP.NET 1.1 Converted Projet : Datagrid problem

    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.

    "Olivier Matrot" <olivier.matrot.rte@online.nospam> wrote in message
    news:O10HriR4FHA.1596@tk2msftngp13.phx.gbl...
    > 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.DataGridCommandEventHand ler(this.dgReceivedHistory_CancelCommand);
    > this.dgReceivedHistory.EditCommand += new
    > System.Web.UI.WebControls.DataGridCommandEventHand ler(this.dgReceivedHistory_EditCommand);
    > this.dgReceivedHistory.UpdateCommand += new
    > System.Web.UI.WebControls.DataGridCommandEventHand ler(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.
    >
    > "Steven Cheng[MSFT]" <stcheng@online.microsoft.com> wrote in message
    > news:d%234HKPP4FHA.3220@TK2MSFTNGXA01.phx.gbl...
    >> 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! [url]www.microsoft.com/security[/url]
    >> (This posting is provided "AS IS", with no warranties, and confers no
    >> rights.)
    >>
    >>
    >>
    >> --------------------
    >> | From: "Olivier Matrot" <olivier.matrot.rte@online.nospam>
    >> | 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: <OBAmWEJ4FHA.3876@TK2MSFTNGP09.phx.gbl>
    >> | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    >> | NNTP-Posting-Host: reverse.completel.net 213.30.138.178
    >> | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP09.phx.gbl
    >> | Xref: TK2MSFTNGXA01.phx.gbl
    >> microsoft.public.dotnet.framework.aspnet.datagridc ontrol:5906
    >> | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    >> |
    >> | 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.
    >> |
    >> |
    >> |
    >> |
    >
    >

    Olivier Matrot Guest

  5. #4

    Default Re: ASP.NET 1.1 Converted Projet : Datagrid problem

    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! [url]www.microsoft.com/security[/url]
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
    --------------------
    | From: "Olivier Matrot" <olivier.matrot.rte@online.nospam>
    | References: <OBAmWEJ4FHA.3876@TK2MSFTNGP09.phx.gbl>
    <d#4HKPP4FHA.3220@TK2MSFTNGXA01.phx.gbl>
    <O10HriR4FHA.1596@tk2msftngp13.phx.gbl>
    | 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: <OLS44gS4FHA.2600@tk2msftngp13.phx.gbl>
    | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    | NNTP-Posting-Host: reverse.completel.net 213.30.138.178
    | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msft ngp13.phx.gbl
    | Xref: TK2MSFTNGXA01.phx.gbl
    microsoft.public.dotnet.framework.aspnet.datagridc ontrol:5916
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    |
    | 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.
    |
    | "Olivier Matrot" <olivier.matrot.rte@online.nospam> wrote in message
    | news:O10HriR4FHA.1596@tk2msftngp13.phx.gbl...
    | > 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.DataGridCommandEventHand ler(this.dgReceivedHistory
    _CancelCommand);
    | > this.dgReceivedHistory.EditCommand += new
    | >
    System.Web.UI.WebControls.DataGridCommandEventHand ler(this.dgReceivedHistory
    _EditCommand);
    | > this.dgReceivedHistory.UpdateCommand += new
    | >
    System.Web.UI.WebControls.DataGridCommandEventHand ler(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.
    | >
    | > "Steven Cheng[MSFT]" <stcheng@online.microsoft.com> wrote in message
    | > news:d%234HKPP4FHA.3220@TK2MSFTNGXA01.phx.gbl...
    | >> 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! [url]www.microsoft.com/security[/url]
    | >> (This posting is provided "AS IS", with no warranties, and confers no
    | >> rights.)
    | >>
    | >>
    | >>
    | >> --------------------
    | >> | From: "Olivier Matrot" <olivier.matrot.rte@online.nospam>
    | >> | 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: <OBAmWEJ4FHA.3876@TK2MSFTNGP09.phx.gbl>
    | >> | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    | >> | NNTP-Posting-Host: reverse.completel.net 213.30.138.178
    | >> | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP09.phx.gbl
    | >> | Xref: TK2MSFTNGXA01.phx.gbl
    | >> microsoft.public.dotnet.framework.aspnet.datagridc ontrol:5906
    | >> | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    | >> |
    | >> | 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.
    | >> |
    | >> |
    | >> |
    | >> |
    | >
    | >
    |
    |
    |

    Steven Cheng[MSFT] Guest

  6. #5

    Default Re: ASP.NET 1.1 Converted Projet : Datagrid problem

    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("ForceDefaultToScri ptImage",
    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[i][n];

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

    x=findObj(n,d.layers[i].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.


    "Steven Cheng[MSFT]" <stcheng@online.microsoft.com> wrote in message
    news:V$GQRMV4FHA.1144@TK2MSFTNGXA01.phx.gbl...
    > 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! [url]www.microsoft.com/security[/url]
    > (This posting is provided "AS IS", with no warranties, and confers no
    > rights.)
    > --------------------
    > | From: "Olivier Matrot" <olivier.matrot.rte@online.nospam>
    > | References: <OBAmWEJ4FHA.3876@TK2MSFTNGP09.phx.gbl>
    > <d#4HKPP4FHA.3220@TK2MSFTNGXA01.phx.gbl>
    > <O10HriR4FHA.1596@tk2msftngp13.phx.gbl>
    > | 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: <OLS44gS4FHA.2600@tk2msftngp13.phx.gbl>
    > | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    > | NNTP-Posting-Host: reverse.completel.net 213.30.138.178
    > | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msft ngp13.phx.gbl
    > | Xref: TK2MSFTNGXA01.phx.gbl
    > microsoft.public.dotnet.framework.aspnet.datagridc ontrol:5916
    > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    > |
    > | 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.
    > |
    > | "Olivier Matrot" <olivier.matrot.rte@online.nospam> wrote in message
    > | news:O10HriR4FHA.1596@tk2msftngp13.phx.gbl...
    > | > 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.DataGridCommandEventHand ler(this.dgReceivedHistory
    > _CancelCommand);
    > | > this.dgReceivedHistory.EditCommand += new
    > | >
    > System.Web.UI.WebControls.DataGridCommandEventHand ler(this.dgReceivedHistory
    > _EditCommand);
    > | > this.dgReceivedHistory.UpdateCommand += new
    > | >
    > System.Web.UI.WebControls.DataGridCommandEventHand ler(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.
    > | >
    > | > "Steven Cheng[MSFT]" <stcheng@online.microsoft.com> wrote in message
    > | > news:d%234HKPP4FHA.3220@TK2MSFTNGXA01.phx.gbl...
    > | >> 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! [url]www.microsoft.com/security[/url]
    > | >> (This posting is provided "AS IS", with no warranties, and confers no
    > | >> rights.)
    > | >>
    > | >>
    > | >>
    > | >> --------------------
    > | >> | From: "Olivier Matrot" <olivier.matrot.rte@online.nospam>
    > | >> | 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: <OBAmWEJ4FHA.3876@TK2MSFTNGP09.phx.gbl>
    > | >> | Newsgroups:
    > microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    > | >> | NNTP-Posting-Host: reverse.completel.net 213.30.138.178
    > | >> | Path:
    > TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP09.phx.gbl
    > | >> | Xref: TK2MSFTNGXA01.phx.gbl
    > | >> microsoft.public.dotnet.framework.aspnet.datagridc ontrol:5906
    > | >> | X-Tomcat-NG:
    > microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    > | >> |
    > | >> | 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.
    > | >> |
    > | >> |
    > | >> |
    > | >> |
    > | >
    >| >
    > |
    > |
    > |
    >

    Olivier Matrot Guest

  7. #6

    Default Re: ASP.NET 1.1 Converted Projet : Datagrid problem

    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! [url]www.microsoft.com/security[/url]
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
    --------------------
    | From: "Olivier Matrot" <olivier.matrot.rte@online.nospam>
    | References: <OBAmWEJ4FHA.3876@TK2MSFTNGP09.phx.gbl>
    <d#4HKPP4FHA.3220@TK2MSFTNGXA01.phx.gbl>
    <O10HriR4FHA.1596@tk2msftngp13.phx.gbl>
    <OLS44gS4FHA.2600@tk2msftngp13.phx.gbl>
    <V$GQRMV4FHA.1144@TK2MSFTNGXA01.phx.gbl>
    | 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: <ONeC86V4FHA.3876@TK2MSFTNGP09.phx.gbl>
    | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    | NNTP-Posting-Host: reverse.completel.net 213.30.138.178
    | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP09.phx.gbl
    | Xref: TK2MSFTNGXA01.phx.gbl
    microsoft.public.dotnet.framework.aspnet.datagridc ontrol:5920
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    |
    | 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("ForceDefaultToScri ptImage",
    | 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[i][n];
    |
    | for(i=0;!x&&d.layers&&i<d.layers.length;i++)
    |
    | x=findObj(n,d.layers[i].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.
    |
    |
    | "Steven Cheng[MSFT]" <stcheng@online.microsoft.com> wrote in message
    | news:V$GQRMV4FHA.1144@TK2MSFTNGXA01.phx.gbl...
    | > 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! [url]www.microsoft.com/security[/url]
    | > (This posting is provided "AS IS", with no warranties, and confers no
    | > rights.)
    | > --------------------
    | > | From: "Olivier Matrot" <olivier.matrot.rte@online.nospam>
    | > | References: <OBAmWEJ4FHA.3876@TK2MSFTNGP09.phx.gbl>
    | > <d#4HKPP4FHA.3220@TK2MSFTNGXA01.phx.gbl>
    | > <O10HriR4FHA.1596@tk2msftngp13.phx.gbl>
    | > | 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: <OLS44gS4FHA.2600@tk2msftngp13.phx.gbl>
    | > | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    | > | NNTP-Posting-Host: reverse.completel.net 213.30.138.178
    | > | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msft ngp13.phx.gbl
    | > | Xref: TK2MSFTNGXA01.phx.gbl
    | > microsoft.public.dotnet.framework.aspnet.datagridc ontrol:5916
    | > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    | > |
    | > | 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.
    | > |
    | > | "Olivier Matrot" <olivier.matrot.rte@online.nospam> wrote in message
    | > | news:O10HriR4FHA.1596@tk2msftngp13.phx.gbl...
    | > | > 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.DataGridCommandEventHand ler(this.dgReceivedHistory
    | > _CancelCommand);
    | > | > this.dgReceivedHistory.EditCommand += new
    | > | >
    | >
    System.Web.UI.WebControls.DataGridCommandEventHand ler(this.dgReceivedHistory
    | > _EditCommand);
    | > | > this.dgReceivedHistory.UpdateCommand += new
    | > | >
    | >
    System.Web.UI.WebControls.DataGridCommandEventHand ler(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.
    | > | >
    | > | > "Steven Cheng[MSFT]" <stcheng@online.microsoft.com> wrote in message
    | > | > news:d%234HKPP4FHA.3220@TK2MSFTNGXA01.phx.gbl...
    | > | >> 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! [url]www.microsoft.com/security[/url]
    | > | >> (This posting is provided "AS IS", with no warranties, and confers
    no
    | > | >> rights.)
    | > | >>
    | > | >>
    | > | >>
    | > | >> --------------------
    | > | >> | From: "Olivier Matrot" <olivier.matrot.rte@online.nospam>
    | > | >> | 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: <OBAmWEJ4FHA.3876@TK2MSFTNGP09.phx.gbl>
    | > | >> | Newsgroups:
    | > microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    | > | >> | NNTP-Posting-Host: reverse.completel.net 213.30.138.178
    | > | >> | Path:
    | > TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP09.phx.gbl
    | > | >> | Xref: TK2MSFTNGXA01.phx.gbl
    | > | >> microsoft.public.dotnet.framework.aspnet.datagridc ontrol:5906
    | > | >> | X-Tomcat-NG:
    | > microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    | > | >> |
    | > | >> | 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.
    | > | >> |
    | > | >> |
    | > | >> |
    | > | >> |
    | > | >
    | >| >
    | > |
    | > |
    | > |
    | >
    |
    |
    |
    Steven Cheng[MSFT] Guest

  8. #7

    Default Re: ASP.NET 1.1 Converted Projet : Datagrid problem

    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[MSFT]" <stcheng@online.microsoft.com> wrote in message
    news:qPswKzr4FHA.3220@TK2MSFTNGXA01.phx.gbl...
    > 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! [url]www.microsoft.com/security[/url]
    > (This posting is provided "AS IS", with no warranties, and confers no
    > rights.)
    > --------------------
    > | From: "Olivier Matrot" <olivier.matrot.rte@online.nospam>
    > | References: <OBAmWEJ4FHA.3876@TK2MSFTNGP09.phx.gbl>
    > <d#4HKPP4FHA.3220@TK2MSFTNGXA01.phx.gbl>
    > <O10HriR4FHA.1596@tk2msftngp13.phx.gbl>
    > <OLS44gS4FHA.2600@tk2msftngp13.phx.gbl>
    > <V$GQRMV4FHA.1144@TK2MSFTNGXA01.phx.gbl>
    > | 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: <ONeC86V4FHA.3876@TK2MSFTNGP09.phx.gbl>
    > | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    > | NNTP-Posting-Host: reverse.completel.net 213.30.138.178
    > | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP09.phx.gbl
    > | Xref: TK2MSFTNGXA01.phx.gbl
    > microsoft.public.dotnet.framework.aspnet.datagridc ontrol:5920
    > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    > |
    > | 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("ForceDefaultToScri ptImage",
    > | 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[i][n];
    > |
    > | for(i=0;!x&&d.layers&&i<d.layers.length;i++)
    > |
    > | x=findObj(n,d.layers[i].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.
    > |
    > |
    > | "Steven Cheng[MSFT]" <stcheng@online.microsoft.com> wrote in message
    > | news:V$GQRMV4FHA.1144@TK2MSFTNGXA01.phx.gbl...
    > | > 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! [url]www.microsoft.com/security[/url]
    > | > (This posting is provided "AS IS", with no warranties, and confers no
    > | > rights.)
    > | > --------------------
    > | > | From: "Olivier Matrot" <olivier.matrot.rte@online.nospam>
    > | > | References: <OBAmWEJ4FHA.3876@TK2MSFTNGP09.phx.gbl>
    > | > <d#4HKPP4FHA.3220@TK2MSFTNGXA01.phx.gbl>
    > | > <O10HriR4FHA.1596@tk2msftngp13.phx.gbl>
    > | > | 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: <OLS44gS4FHA.2600@tk2msftngp13.phx.gbl>
    > | > | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    > | > | NNTP-Posting-Host: reverse.completel.net 213.30.138.178
    > | > | Path:
    > TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msft ngp13.phx.gbl
    > | > | Xref: TK2MSFTNGXA01.phx.gbl
    > | > microsoft.public.dotnet.framework.aspnet.datagridc ontrol:5916
    > | > | X-Tomcat-NG:
    > microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    > | > |
    > | > | 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.
    > | > |
    > | > | "Olivier Matrot" <olivier.matrot.rte@online.nospam> wrote in message
    > | > | news:O10HriR4FHA.1596@tk2msftngp13.phx.gbl...
    > | > | > 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.DataGridCommandEventHand ler(this.dgReceivedHistory
    > | > _CancelCommand);
    > | > | > this.dgReceivedHistory.EditCommand += new
    > | > | >
    > | >
    > System.Web.UI.WebControls.DataGridCommandEventHand ler(this.dgReceivedHistory
    > | > _EditCommand);
    > | > | > this.dgReceivedHistory.UpdateCommand += new
    > | > | >
    > | >
    > System.Web.UI.WebControls.DataGridCommandEventHand ler(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.
    > | > | >
    > | > | > "Steven Cheng[MSFT]" <stcheng@online.microsoft.com> wrote in
    > message
    > | > | > news:d%234HKPP4FHA.3220@TK2MSFTNGXA01.phx.gbl...
    > | > | >> 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! [url]www.microsoft.com/security[/url]
    > | > | >> (This posting is provided "AS IS", with no warranties, and
    > confers
    > no
    > | > | >> rights.)
    > | > | >>
    > | > | >>
    > | > | >>
    > | > | >> --------------------
    > | > | >> | From: "Olivier Matrot" <olivier.matrot.rte@online.nospam>
    > | > | >> | 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: <OBAmWEJ4FHA.3876@TK2MSFTNGP09.phx.gbl>
    > | > | >> | Newsgroups:
    > | > microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    > | > | >> | NNTP-Posting-Host: reverse.completel.net 213.30.138.178
    > | > | >> | Path:
    > | > TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP09.phx.gbl
    > | > | >> | Xref: TK2MSFTNGXA01.phx.gbl
    > | > | >> microsoft.public.dotnet.framework.aspnet.datagridc ontrol:5906
    > | > | >> | X-Tomcat-NG:
    > | > microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    > | > | >> |
    > | > | >> | 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.
    > | > | >> |
    > | > | >> |
    > | > | >> |
    > | > | >> |
    > | > | >
    > | >| >
    > | > |
    > | > |
    > | > |
    > | >
    > |
    > |
    > |

    Olivier Matrot Guest

  9. #8

    Default Re: ASP.NET 1.1 Converted Projet : Datagrid problem

    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! [url]www.microsoft.com/security[/url]
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
    --------------------
    | From: "Olivier Matrot" <olivier.matrot.rte@online.nospam>
    | References: <OBAmWEJ4FHA.3876@TK2MSFTNGP09.phx.gbl>
    <d#4HKPP4FHA.3220@TK2MSFTNGXA01.phx.gbl>
    <O10HriR4FHA.1596@tk2msftngp13.phx.gbl>
    <OLS44gS4FHA.2600@tk2msftngp13.phx.gbl>
    <V$GQRMV4FHA.1144@TK2MSFTNGXA01.phx.gbl>
    <ONeC86V4FHA.3876@TK2MSFTNGP09.phx.gbl>
    <qPswKzr4FHA.3220@TK2MSFTNGXA01.phx.gbl>
    | 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: <uxzr0K34FHA.3188@TK2MSFTNGP15.phx.gbl>
    | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    | NNTP-Posting-Host: reverse.completel.net 213.30.138.178
    | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP15.phx.gbl
    | Xref: TK2MSFTNGXA01.phx.gbl
    microsoft.public.dotnet.framework.aspnet.datagridc ontrol:5943
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    |
    | 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[MSFT]" <stcheng@online.microsoft.com> wrote in message
    | news:qPswKzr4FHA.3220@TK2MSFTNGXA01.phx.gbl...
    | > 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! [url]www.microsoft.com/security[/url]
    | > (This posting is provided "AS IS", with no warranties, and confers no
    | > rights.)
    | > --------------------
    | > | From: "Olivier Matrot" <olivier.matrot.rte@online.nospam>
    | > | References: <OBAmWEJ4FHA.3876@TK2MSFTNGP09.phx.gbl>
    | > <d#4HKPP4FHA.3220@TK2MSFTNGXA01.phx.gbl>
    | > <O10HriR4FHA.1596@tk2msftngp13.phx.gbl>
    | > <OLS44gS4FHA.2600@tk2msftngp13.phx.gbl>
    | > <V$GQRMV4FHA.1144@TK2MSFTNGXA01.phx.gbl>
    | > | 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: <ONeC86V4FHA.3876@TK2MSFTNGP09.phx.gbl>
    | > | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    | > | NNTP-Posting-Host: reverse.completel.net 213.30.138.178
    | > | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP09.phx.gbl
    | > | Xref: TK2MSFTNGXA01.phx.gbl
    | > microsoft.public.dotnet.framework.aspnet.datagridc ontrol:5920
    | > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    | > |
    | > | 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("ForceDefaultToScri ptImage",
    | > | 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[i][n];
    | > |
    | > | for(i=0;!x&&d.layers&&i<d.layers.length;i++)
    | > |
    | > | x=findObj(n,d.layers[i].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.
    | > |
    | > |
    | > | "Steven Cheng[MSFT]" <stcheng@online.microsoft.com> wrote in message
    | > | news:V$GQRMV4FHA.1144@TK2MSFTNGXA01.phx.gbl...
    | > | > 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! [url]www.microsoft.com/security[/url]
    | > | > (This posting is provided "AS IS", with no warranties, and confers
    no
    | > | > rights.)
    | > | > --------------------
    | > | > | From: "Olivier Matrot" <olivier.matrot.rte@online.nospam>
    | > | > | References: <OBAmWEJ4FHA.3876@TK2MSFTNGP09.phx.gbl>
    | > | > <d#4HKPP4FHA.3220@TK2MSFTNGXA01.phx.gbl>
    | > | > <O10HriR4FHA.1596@tk2msftngp13.phx.gbl>
    | > | > | 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: <OLS44gS4FHA.2600@tk2msftngp13.phx.gbl>
    | > | > | Newsgroups:
    microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    | > | > | NNTP-Posting-Host: reverse.completel.net 213.30.138.178
    | > | > | Path:
    | > TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msft ngp13.phx.gbl
    | > | > | Xref: TK2MSFTNGXA01.phx.gbl
    | > | > microsoft.public.dotnet.framework.aspnet.datagridc ontrol:5916
    | > | > | X-Tomcat-NG:
    | > microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    | > | > |
    | > | > | 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.
    | > | > |
    | > | > | "Olivier Matrot" <olivier.matrot.rte@online.nospam> wrote in
    message
    | > | > | news:O10HriR4FHA.1596@tk2msftngp13.phx.gbl...
    | > | > | > 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.DataGridCommandEventHand ler(this.dgReceivedHistory
    | > | > _CancelCommand);
    | > | > | > this.dgReceivedHistory.EditCommand += new
    | > | > | >
    | > | >
    | >
    System.Web.UI.WebControls.DataGridCommandEventHand ler(this.dgReceivedHistory
    | > | > _EditCommand);
    | > | > | > this.dgReceivedHistory.UpdateCommand += new
    | > | > | >
    | > | >
    | >
    System.Web.UI.WebControls.DataGridCommandEventHand ler(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.
    | > | > | >
    | > | > | > "Steven Cheng[MSFT]" <stcheng@online.microsoft.com> wrote in
    | > message
    | > | > | > news:d%234HKPP4FHA.3220@TK2MSFTNGXA01.phx.gbl...
    | > | > | >> 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! [url]www.microsoft.com/security[/url]
    | > | > | >> (This posting is provided "AS IS", with no warranties, and
    | > confers
    | > no
    | > | > | >> rights.)
    | > | > | >>
    | > | > | >>
    | > | > | >>
    | > | > | >> --------------------
    | > | > | >> | From: "Olivier Matrot" <olivier.matrot.rte@online.nospam>
    | > | > | >> | 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: <OBAmWEJ4FHA.3876@TK2MSFTNGP09.phx.gbl>
    | > | > | >> | Newsgroups:
    | > | > microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    | > | > | >> | NNTP-Posting-Host: reverse.completel.net 213.30.138.178
    | > | > | >> | Path:
    | > | > TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP09.phx.gbl
    | > | > | >> | Xref: TK2MSFTNGXA01.phx.gbl
    | > | > | >> microsoft.public.dotnet.framework.aspnet.datagridc ontrol:5906
    | > | > | >> | X-Tomcat-NG:
    | > | > microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    | > | > | >> |
    | > | > | >> | 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.
    | > | > | >> |
    | > | > | >> |
    | > | > | >> |
    | > | > | >> |
    | > | > | >
    | > | >| >
    | > | > |
    | > | > |
    | > | > |
    | > | >
    | > |
    | > |
    | > |
    |
    |
    |

    Steven Cheng[MSFT] Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139