Gridview inside UpdatePanel Deleting Records, Updating Wrong Rows










2















I have several gridviews each inside their own UpdatePanels. I have buttons that filter the data but have noticed unusual updating and deletions at times that I cannot detect the source of. One thing I have isolated is that this occurs when I sort a gridviews data in one UpdatePanel and then try to update another UpdatePanel.



(My gridviews all get their data from the same DataLoad procedure that populates each gridview based on different Linq queries.)



I resolved most of the unusual updates by calling .Update() on all UpdatePanels after my sorting function so all gridviews are "refreshed". But then there are still some instances were data is getting updated and I can not isolate the source.



It looks like data outside one UpdatePanel is actually being updated "behind the scenes" and only cached data is on the screen and then when I edit what is on the screen, wrong data gets updated because it was not refreshed.



I am guessing that my sorting strategy is incorrect as I am sorting all gridviews instead of just that specific gridview when user clicks a column header.



Here is my sorting procedure that is called by each gridview:



protected void TaskGridView_Sorting(object sender, GridViewSortEventArgs e)

string sortExp = ViewState["SortExpression"] as string;
string sortDir = ViewState["SortDirection"] as string;
if(sortDir == "asc" & sortExp == e.SortExpression.ToString())
ViewState["SortDirection"] = "desc";
else
ViewState["SortDirection"] = "asc";
ViewState["SortExpression"] = e.SortExpression.ToString();

if(searchCol != "" && searchText != "")
DataGrid_Load(DAL.Search_reg_log(OrgText.Text, searchText, searchCol), "reg");
else
DataGrid_Load(DAL.reg_log(HeadText.Text, OrgText.Text), "reg");

UpdatePanels();




I am new to using Ajax and UpdatePanels and would like any direction on resolving this situation.










share|improve this question






















  • stackoverflow.com/questions/53438582/… is a more detailed description of this issue.

    – jroyce
    Nov 25 '18 at 16:58















2















I have several gridviews each inside their own UpdatePanels. I have buttons that filter the data but have noticed unusual updating and deletions at times that I cannot detect the source of. One thing I have isolated is that this occurs when I sort a gridviews data in one UpdatePanel and then try to update another UpdatePanel.



(My gridviews all get their data from the same DataLoad procedure that populates each gridview based on different Linq queries.)



I resolved most of the unusual updates by calling .Update() on all UpdatePanels after my sorting function so all gridviews are "refreshed". But then there are still some instances were data is getting updated and I can not isolate the source.



It looks like data outside one UpdatePanel is actually being updated "behind the scenes" and only cached data is on the screen and then when I edit what is on the screen, wrong data gets updated because it was not refreshed.



I am guessing that my sorting strategy is incorrect as I am sorting all gridviews instead of just that specific gridview when user clicks a column header.



Here is my sorting procedure that is called by each gridview:



protected void TaskGridView_Sorting(object sender, GridViewSortEventArgs e)

string sortExp = ViewState["SortExpression"] as string;
string sortDir = ViewState["SortDirection"] as string;
if(sortDir == "asc" & sortExp == e.SortExpression.ToString())
ViewState["SortDirection"] = "desc";
else
ViewState["SortDirection"] = "asc";
ViewState["SortExpression"] = e.SortExpression.ToString();

if(searchCol != "" && searchText != "")
DataGrid_Load(DAL.Search_reg_log(OrgText.Text, searchText, searchCol), "reg");
else
DataGrid_Load(DAL.reg_log(HeadText.Text, OrgText.Text), "reg");

UpdatePanels();




I am new to using Ajax and UpdatePanels and would like any direction on resolving this situation.










share|improve this question






















  • stackoverflow.com/questions/53438582/… is a more detailed description of this issue.

    – jroyce
    Nov 25 '18 at 16:58













2












2








2


3






I have several gridviews each inside their own UpdatePanels. I have buttons that filter the data but have noticed unusual updating and deletions at times that I cannot detect the source of. One thing I have isolated is that this occurs when I sort a gridviews data in one UpdatePanel and then try to update another UpdatePanel.



(My gridviews all get their data from the same DataLoad procedure that populates each gridview based on different Linq queries.)



I resolved most of the unusual updates by calling .Update() on all UpdatePanels after my sorting function so all gridviews are "refreshed". But then there are still some instances were data is getting updated and I can not isolate the source.



It looks like data outside one UpdatePanel is actually being updated "behind the scenes" and only cached data is on the screen and then when I edit what is on the screen, wrong data gets updated because it was not refreshed.



I am guessing that my sorting strategy is incorrect as I am sorting all gridviews instead of just that specific gridview when user clicks a column header.



Here is my sorting procedure that is called by each gridview:



protected void TaskGridView_Sorting(object sender, GridViewSortEventArgs e)

string sortExp = ViewState["SortExpression"] as string;
string sortDir = ViewState["SortDirection"] as string;
if(sortDir == "asc" & sortExp == e.SortExpression.ToString())
ViewState["SortDirection"] = "desc";
else
ViewState["SortDirection"] = "asc";
ViewState["SortExpression"] = e.SortExpression.ToString();

if(searchCol != "" && searchText != "")
DataGrid_Load(DAL.Search_reg_log(OrgText.Text, searchText, searchCol), "reg");
else
DataGrid_Load(DAL.reg_log(HeadText.Text, OrgText.Text), "reg");

UpdatePanels();




I am new to using Ajax and UpdatePanels and would like any direction on resolving this situation.










share|improve this question














I have several gridviews each inside their own UpdatePanels. I have buttons that filter the data but have noticed unusual updating and deletions at times that I cannot detect the source of. One thing I have isolated is that this occurs when I sort a gridviews data in one UpdatePanel and then try to update another UpdatePanel.



(My gridviews all get their data from the same DataLoad procedure that populates each gridview based on different Linq queries.)



I resolved most of the unusual updates by calling .Update() on all UpdatePanels after my sorting function so all gridviews are "refreshed". But then there are still some instances were data is getting updated and I can not isolate the source.



It looks like data outside one UpdatePanel is actually being updated "behind the scenes" and only cached data is on the screen and then when I edit what is on the screen, wrong data gets updated because it was not refreshed.



I am guessing that my sorting strategy is incorrect as I am sorting all gridviews instead of just that specific gridview when user clicks a column header.



Here is my sorting procedure that is called by each gridview:



protected void TaskGridView_Sorting(object sender, GridViewSortEventArgs e)

string sortExp = ViewState["SortExpression"] as string;
string sortDir = ViewState["SortDirection"] as string;
if(sortDir == "asc" & sortExp == e.SortExpression.ToString())
ViewState["SortDirection"] = "desc";
else
ViewState["SortDirection"] = "asc";
ViewState["SortExpression"] = e.SortExpression.ToString();

if(searchCol != "" && searchText != "")
DataGrid_Load(DAL.Search_reg_log(OrgText.Text, searchText, searchCol), "reg");
else
DataGrid_Load(DAL.reg_log(HeadText.Text, OrgText.Text), "reg");

UpdatePanels();




I am new to using Ajax and UpdatePanels and would like any direction on resolving this situation.







c# asp.net ajax gridview updatepanel






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 15 '18 at 19:37









jroycejroyce

1,49121637




1,49121637












  • stackoverflow.com/questions/53438582/… is a more detailed description of this issue.

    – jroyce
    Nov 25 '18 at 16:58

















  • stackoverflow.com/questions/53438582/… is a more detailed description of this issue.

    – jroyce
    Nov 25 '18 at 16:58
















stackoverflow.com/questions/53438582/… is a more detailed description of this issue.

– jroyce
Nov 25 '18 at 16:58





stackoverflow.com/questions/53438582/… is a more detailed description of this issue.

– jroyce
Nov 25 '18 at 16:58












2 Answers
2






active

oldest

votes


















3





+25









There is nothing wrong with your code you posted. The problem is not in that snippet and has nothing to do with ViewState or an UpdatePanel. If you are unsure what is happening it helps to visualize it. Either by debugging or just display the result in a Label and see if it is what you expect it to be.



protected void TaskGridView_Sorting(object sender, GridViewSortEventArgs e)

//load the previous sorting settings
string sortExp = ViewState["SortExpression"] as string;
string sortDir = ViewState["SortDirection"] as string;

//reverse the direction if the column is the same as the previous sort
if (sortDir == "asc" & sortExp == e.SortExpression.ToString())
ViewState["SortDirection"] = "desc";
else
ViewState["SortDirection"] = "asc";

//put the current sort column in the viewstate
ViewState["SortExpression"] = e.SortExpression.ToString();

//show sorting result in a literal for testing
Literal1.Text = ViewState["SortExpression"] + " " + ViewState["SortDirection"];

//rebind data
if (searchCol != "" && searchText != "")
DataGrid_Load(DAL.Search_reg_log(OrgText.Text, searchText, searchCol), "reg");
else
DataGrid_Load(DAL.reg_log(HeadText.Text, OrgText.Text), "reg");

//update the updatepanels
UpdatePanels();






share|improve this answer






























    2














    Use properties for ViewState it could be caused by Post Process of your PostBack



    private string p_SortExp

    get

    if (ViewState["p_SortExp"] != null)

    return ViewState["dtSupplierList"] as string;

    else

    return null;


    set

    ViewState["p_SortExp"] = value;




    then in your function try calling the properties and remember to set them at the right functions for better usability






    share|improve this answer























    • Thanks for your reply. Is the above C#?

      – jroyce
      Nov 27 '18 at 0:45











    • Yes it is a C# language, ASP.NET

      – Richard Mark Bonifacio
      Nov 27 '18 at 0:55











    • Thanks I’ll try this out and see if it resolves my issue. Can you also look at my other post which gives more detail?

      – jroyce
      Nov 27 '18 at 0:59











    • Yes, you may. Just update this trend for me to be notified. It would be better if you can show us more detailed info about your post. Like the update panel update mode or how and where you assign your variables this will help us to locate where the problem happen

      – Richard Mark Bonifacio
      Nov 27 '18 at 1:03











    • I believe I already am using ViewState. Please look at my code and the example posted here: stackoverflow.com/questions/53438582/…

      – jroyce
      Nov 29 '18 at 12:31










    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53326793%2fgridview-inside-updatepanel-deleting-records-updating-wrong-rows%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3





    +25









    There is nothing wrong with your code you posted. The problem is not in that snippet and has nothing to do with ViewState or an UpdatePanel. If you are unsure what is happening it helps to visualize it. Either by debugging or just display the result in a Label and see if it is what you expect it to be.



    protected void TaskGridView_Sorting(object sender, GridViewSortEventArgs e)

    //load the previous sorting settings
    string sortExp = ViewState["SortExpression"] as string;
    string sortDir = ViewState["SortDirection"] as string;

    //reverse the direction if the column is the same as the previous sort
    if (sortDir == "asc" & sortExp == e.SortExpression.ToString())
    ViewState["SortDirection"] = "desc";
    else
    ViewState["SortDirection"] = "asc";

    //put the current sort column in the viewstate
    ViewState["SortExpression"] = e.SortExpression.ToString();

    //show sorting result in a literal for testing
    Literal1.Text = ViewState["SortExpression"] + " " + ViewState["SortDirection"];

    //rebind data
    if (searchCol != "" && searchText != "")
    DataGrid_Load(DAL.Search_reg_log(OrgText.Text, searchText, searchCol), "reg");
    else
    DataGrid_Load(DAL.reg_log(HeadText.Text, OrgText.Text), "reg");

    //update the updatepanels
    UpdatePanels();






    share|improve this answer



























      3





      +25









      There is nothing wrong with your code you posted. The problem is not in that snippet and has nothing to do with ViewState or an UpdatePanel. If you are unsure what is happening it helps to visualize it. Either by debugging or just display the result in a Label and see if it is what you expect it to be.



      protected void TaskGridView_Sorting(object sender, GridViewSortEventArgs e)

      //load the previous sorting settings
      string sortExp = ViewState["SortExpression"] as string;
      string sortDir = ViewState["SortDirection"] as string;

      //reverse the direction if the column is the same as the previous sort
      if (sortDir == "asc" & sortExp == e.SortExpression.ToString())
      ViewState["SortDirection"] = "desc";
      else
      ViewState["SortDirection"] = "asc";

      //put the current sort column in the viewstate
      ViewState["SortExpression"] = e.SortExpression.ToString();

      //show sorting result in a literal for testing
      Literal1.Text = ViewState["SortExpression"] + " " + ViewState["SortDirection"];

      //rebind data
      if (searchCol != "" && searchText != "")
      DataGrid_Load(DAL.Search_reg_log(OrgText.Text, searchText, searchCol), "reg");
      else
      DataGrid_Load(DAL.reg_log(HeadText.Text, OrgText.Text), "reg");

      //update the updatepanels
      UpdatePanels();






      share|improve this answer

























        3





        +25







        3





        +25



        3




        +25





        There is nothing wrong with your code you posted. The problem is not in that snippet and has nothing to do with ViewState or an UpdatePanel. If you are unsure what is happening it helps to visualize it. Either by debugging or just display the result in a Label and see if it is what you expect it to be.



        protected void TaskGridView_Sorting(object sender, GridViewSortEventArgs e)

        //load the previous sorting settings
        string sortExp = ViewState["SortExpression"] as string;
        string sortDir = ViewState["SortDirection"] as string;

        //reverse the direction if the column is the same as the previous sort
        if (sortDir == "asc" & sortExp == e.SortExpression.ToString())
        ViewState["SortDirection"] = "desc";
        else
        ViewState["SortDirection"] = "asc";

        //put the current sort column in the viewstate
        ViewState["SortExpression"] = e.SortExpression.ToString();

        //show sorting result in a literal for testing
        Literal1.Text = ViewState["SortExpression"] + " " + ViewState["SortDirection"];

        //rebind data
        if (searchCol != "" && searchText != "")
        DataGrid_Load(DAL.Search_reg_log(OrgText.Text, searchText, searchCol), "reg");
        else
        DataGrid_Load(DAL.reg_log(HeadText.Text, OrgText.Text), "reg");

        //update the updatepanels
        UpdatePanels();






        share|improve this answer













        There is nothing wrong with your code you posted. The problem is not in that snippet and has nothing to do with ViewState or an UpdatePanel. If you are unsure what is happening it helps to visualize it. Either by debugging or just display the result in a Label and see if it is what you expect it to be.



        protected void TaskGridView_Sorting(object sender, GridViewSortEventArgs e)

        //load the previous sorting settings
        string sortExp = ViewState["SortExpression"] as string;
        string sortDir = ViewState["SortDirection"] as string;

        //reverse the direction if the column is the same as the previous sort
        if (sortDir == "asc" & sortExp == e.SortExpression.ToString())
        ViewState["SortDirection"] = "desc";
        else
        ViewState["SortDirection"] = "asc";

        //put the current sort column in the viewstate
        ViewState["SortExpression"] = e.SortExpression.ToString();

        //show sorting result in a literal for testing
        Literal1.Text = ViewState["SortExpression"] + " " + ViewState["SortDirection"];

        //rebind data
        if (searchCol != "" && searchText != "")
        DataGrid_Load(DAL.Search_reg_log(OrgText.Text, searchText, searchCol), "reg");
        else
        DataGrid_Load(DAL.reg_log(HeadText.Text, OrgText.Text), "reg");

        //update the updatepanels
        UpdatePanels();







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 27 '18 at 8:37









        VDWWDVDWWD

        24.2k113654




        24.2k113654























            2














            Use properties for ViewState it could be caused by Post Process of your PostBack



            private string p_SortExp

            get

            if (ViewState["p_SortExp"] != null)

            return ViewState["dtSupplierList"] as string;

            else

            return null;


            set

            ViewState["p_SortExp"] = value;




            then in your function try calling the properties and remember to set them at the right functions for better usability






            share|improve this answer























            • Thanks for your reply. Is the above C#?

              – jroyce
              Nov 27 '18 at 0:45











            • Yes it is a C# language, ASP.NET

              – Richard Mark Bonifacio
              Nov 27 '18 at 0:55











            • Thanks I’ll try this out and see if it resolves my issue. Can you also look at my other post which gives more detail?

              – jroyce
              Nov 27 '18 at 0:59











            • Yes, you may. Just update this trend for me to be notified. It would be better if you can show us more detailed info about your post. Like the update panel update mode or how and where you assign your variables this will help us to locate where the problem happen

              – Richard Mark Bonifacio
              Nov 27 '18 at 1:03











            • I believe I already am using ViewState. Please look at my code and the example posted here: stackoverflow.com/questions/53438582/…

              – jroyce
              Nov 29 '18 at 12:31















            2














            Use properties for ViewState it could be caused by Post Process of your PostBack



            private string p_SortExp

            get

            if (ViewState["p_SortExp"] != null)

            return ViewState["dtSupplierList"] as string;

            else

            return null;


            set

            ViewState["p_SortExp"] = value;




            then in your function try calling the properties and remember to set them at the right functions for better usability






            share|improve this answer























            • Thanks for your reply. Is the above C#?

              – jroyce
              Nov 27 '18 at 0:45











            • Yes it is a C# language, ASP.NET

              – Richard Mark Bonifacio
              Nov 27 '18 at 0:55











            • Thanks I’ll try this out and see if it resolves my issue. Can you also look at my other post which gives more detail?

              – jroyce
              Nov 27 '18 at 0:59











            • Yes, you may. Just update this trend for me to be notified. It would be better if you can show us more detailed info about your post. Like the update panel update mode or how and where you assign your variables this will help us to locate where the problem happen

              – Richard Mark Bonifacio
              Nov 27 '18 at 1:03











            • I believe I already am using ViewState. Please look at my code and the example posted here: stackoverflow.com/questions/53438582/…

              – jroyce
              Nov 29 '18 at 12:31













            2












            2








            2







            Use properties for ViewState it could be caused by Post Process of your PostBack



            private string p_SortExp

            get

            if (ViewState["p_SortExp"] != null)

            return ViewState["dtSupplierList"] as string;

            else

            return null;


            set

            ViewState["p_SortExp"] = value;




            then in your function try calling the properties and remember to set them at the right functions for better usability






            share|improve this answer













            Use properties for ViewState it could be caused by Post Process of your PostBack



            private string p_SortExp

            get

            if (ViewState["p_SortExp"] != null)

            return ViewState["dtSupplierList"] as string;

            else

            return null;


            set

            ViewState["p_SortExp"] = value;




            then in your function try calling the properties and remember to set them at the right functions for better usability







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 27 '18 at 0:41









            Richard Mark BonifacioRichard Mark Bonifacio

            5118




            5118












            • Thanks for your reply. Is the above C#?

              – jroyce
              Nov 27 '18 at 0:45











            • Yes it is a C# language, ASP.NET

              – Richard Mark Bonifacio
              Nov 27 '18 at 0:55











            • Thanks I’ll try this out and see if it resolves my issue. Can you also look at my other post which gives more detail?

              – jroyce
              Nov 27 '18 at 0:59











            • Yes, you may. Just update this trend for me to be notified. It would be better if you can show us more detailed info about your post. Like the update panel update mode or how and where you assign your variables this will help us to locate where the problem happen

              – Richard Mark Bonifacio
              Nov 27 '18 at 1:03











            • I believe I already am using ViewState. Please look at my code and the example posted here: stackoverflow.com/questions/53438582/…

              – jroyce
              Nov 29 '18 at 12:31

















            • Thanks for your reply. Is the above C#?

              – jroyce
              Nov 27 '18 at 0:45











            • Yes it is a C# language, ASP.NET

              – Richard Mark Bonifacio
              Nov 27 '18 at 0:55











            • Thanks I’ll try this out and see if it resolves my issue. Can you also look at my other post which gives more detail?

              – jroyce
              Nov 27 '18 at 0:59











            • Yes, you may. Just update this trend for me to be notified. It would be better if you can show us more detailed info about your post. Like the update panel update mode or how and where you assign your variables this will help us to locate where the problem happen

              – Richard Mark Bonifacio
              Nov 27 '18 at 1:03











            • I believe I already am using ViewState. Please look at my code and the example posted here: stackoverflow.com/questions/53438582/…

              – jroyce
              Nov 29 '18 at 12:31
















            Thanks for your reply. Is the above C#?

            – jroyce
            Nov 27 '18 at 0:45





            Thanks for your reply. Is the above C#?

            – jroyce
            Nov 27 '18 at 0:45













            Yes it is a C# language, ASP.NET

            – Richard Mark Bonifacio
            Nov 27 '18 at 0:55





            Yes it is a C# language, ASP.NET

            – Richard Mark Bonifacio
            Nov 27 '18 at 0:55













            Thanks I’ll try this out and see if it resolves my issue. Can you also look at my other post which gives more detail?

            – jroyce
            Nov 27 '18 at 0:59





            Thanks I’ll try this out and see if it resolves my issue. Can you also look at my other post which gives more detail?

            – jroyce
            Nov 27 '18 at 0:59













            Yes, you may. Just update this trend for me to be notified. It would be better if you can show us more detailed info about your post. Like the update panel update mode or how and where you assign your variables this will help us to locate where the problem happen

            – Richard Mark Bonifacio
            Nov 27 '18 at 1:03





            Yes, you may. Just update this trend for me to be notified. It would be better if you can show us more detailed info about your post. Like the update panel update mode or how and where you assign your variables this will help us to locate where the problem happen

            – Richard Mark Bonifacio
            Nov 27 '18 at 1:03













            I believe I already am using ViewState. Please look at my code and the example posted here: stackoverflow.com/questions/53438582/…

            – jroyce
            Nov 29 '18 at 12:31





            I believe I already am using ViewState. Please look at my code and the example posted here: stackoverflow.com/questions/53438582/…

            – jroyce
            Nov 29 '18 at 12:31

















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53326793%2fgridview-inside-updatepanel-deleting-records-updating-wrong-rows%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Top Tejano songwriter Luis Silva dead of heart attack at 64

            政党

            天津地下鉄3号線