Details View -- Losing what i typed

Last post 10-25-2006 11:10 AM by CraigMcF. 8 replies.

Sort Posts:

  • Details View -- Losing what i typed

    09-20-2006, 1:12 PM
    • Loading...
    • eamonroche
    • Joined on 12-22-2005, 4:34 PM
    • Posts 60

    I have a DetailsView bound to a Sql Server datasource

    When i click the "update" button, a stored procedure is executed, which tests to see if the submitted values are appropriate and returns an error message if the item could not be updated.

    However, because the DetailsView re-binds on a post back i have now lost what i have typed into the boxes.

    Sure, i can manually save the entered data into variables during the DetailsView_OnUpdating event and recall these, if necessary, on the DetailsView_DataBound event but this is very time consuming.

    Is there an easier way? Thanks in advance

  • Re: Details View -- Losing what i typed

    09-21-2006, 3:45 AM
    • Loading...
    • rexlin
    • Joined on 07-17-2006, 8:43 AM
    • Posts 1,751

    Hi,eamonroche:

    I suppose that you can use viewstate to set and get the value you typed.



    Best Regards,
    __________________________________________________
    Sincerely,
    Rex Lin
    Microsoft Online Community Support

    This posting is provided "AS IS" with on warranties, and confers no rights.
  • Re: Details View -- Losing what i typed

    09-21-2006, 4:43 AM
    • Loading...
    • eamonroche
    • Joined on 12-22-2005, 4:34 PM
    • Posts 60

    Use viewstate?

    Do you mean through the DetailsView_OnUpdating and DetailsView_DataBound events still - or do you mean something else?

    Thanks

  • Re: Details View -- Losing what i typed

    09-21-2006, 8:55 AM
    • Loading...
    • hoopslife
    • Joined on 12-29-2005, 2:29 PM
    • Fort Myers, FL
    • Posts 263
    Never Quit
  • Re: Details View -- Losing what i typed

    09-21-2006, 4:36 PM
    Answer
    • Loading...
    • docluv
    • Joined on 06-29-2002, 11:16 PM
    • Willow Spring NC
    • Posts 1,488
    • TrustedFriends-MVPs

    Don't do that, it will lead to poor performance and probably not help you

     You will have to avoid rebinding the data to your datacontrol when the page is posted back.  In the Page_load event handler use IsPastback to control this.  Once you have stored the data then call your databind method.

    private sub Page_Load [Handler Code will be here] 

     If not ispostback then

        BindData

    end if

    end sub

    private sub UpdateEventHandler

     ''''' Store Your Data here

    BindData 

    end sub 

     

  • Re: Details View -- Losing what i typed

    09-25-2006, 5:38 AM
    • Loading...
    • eamonroche
    • Joined on 12-22-2005, 4:34 PM
    • Posts 60

    thanks docluv

    but the databing for a detailsview is done automatically...there is no explicit BindData function that i can disable within an "If not ispostback" question.

    it would be great if i knew how to turn off this automatic databinding

     

  • Re: Details View -- Losing what i typed

    10-24-2006, 3:59 PM
    • Loading...
    • CraigMcF
    • Joined on 10-24-2006, 3:42 PM
    • Posts 2

    Hi, if you want to disable the automatic databinding you could do the following in the page load:

     
    If IsPostBack then

        DetailsView.DataSourceID="" 

    end if
     

    This will unbind the DetailsView from the sqlDataSource Control

    Regards,

    Craig 

  • Re: Details View -- Losing what i typed

    10-25-2006, 4:52 AM
    • Loading...
    • eamonroche
    • Joined on 12-22-2005, 4:34 PM
    • Posts 60

    Thanks Craig. I will try this.

    Eamon

  • Re: Details View -- Losing what i typed

    10-25-2006, 11:10 AM
    • Loading...
    • CraigMcF
    • Joined on 10-24-2006, 3:42 PM
    • Posts 2

    Hi Eamon

    On second thought you may need to put this in the Page_PreLoad event. The onload even may be too late and may have already encountered the error.

    Regards,

    Craig
     

Page 1 of 1 (9 items)
Microsoft Communities
Page view counter