Validator problem in UpdatePanel

Discussion in 'ASP .Net' started by SAL, Dec 12, 2008.

  1. SAL

    SAL Guest

    Hello,
    Yes, I've read that Validator controls are not compatible inside
    updatePanels. I have downloaded the Validators.dll file and added the
    tagMapping to my web.config file so I'm thinking the validators should work
    right???
    ClientSideScript is disabled.

    Here's the gist of the problem.

    I have an app with a GridView, in an update panel, and a DetailsView, inside
    another update panel. The DetailsView is used for both inserting new records
    and editing existing records.

    There a dropdownlist in the updatepanel for inserting/editing and when a
    user selects an item from this dropdown, a dropdown inside the DetailsView
    populates with the appropriate items for that category.
    If the user then clicks the insert link in the DetailsView, the
    requiredfieldvalidator fires off showing it's text and it's error message
    displays in the ValidationSummary control. This works great.
    However, if a user clicks the Editing button in the top UpdatePanel in one
    of the rows of the GridView and then clicks the cancel button of the
    DetailsView, validation appears to still work but the validators error
    message and text no longer will display.
    This same behavoir shows up for the CustomValidator I have for the same
    field in the DetailsView.

    Is there a way to work around this issue or is it just something in the way
    that I've configured my application?
    I've created a Repro project can e-mail it. It was too large for this post a
    little over 1/2 mb.

    Steps to re-create the issue.
    Sequence 1
    open the project and run it. I have it set up to startup using cntyAssetId =
    1709
    select an item from the dropdownlist just above the details view.
    click the insert button and the RequiredFieldValidator displays its text and
    the ValidationSummary control displays the error msg.

    Sequence 2
    Click the pencil icon for one of the rows in the GridView. The DetailsView
    populates with the record.
    Click the cancel button in the Detailsview
    The DetailsView returns to Insert mode.

    Repeat Sequence 1

    Sequence 3
    To test for the CustomValidator, repeat Sequence 1 and enter a non-valid
    StmFacilityClkId like 999999.
    The CustomValidator works as expected.
    Repeat Sequence 2
    Repeat Sequence 3 and the validator, while still preventing a record from
    being added, the validators text and error message no longer display.

    Any help is much appreciated on this. I googled and googled on it and tried
    lots of things.

    SAL
     
    SAL, Dec 12, 2008
    #1
    1. Advertising

  2. Hi SAL,

    Could you send me that demo project? I'd like to repro it on my side first.

    My email is . Please update here after sending the
    project in case I missed that email.


    Regards,
    Allen Chen
    Microsoft Online Support

    Delighting our customers is our #1 priority. We welcome your comments and
    suggestions about how we can improve the support we provide to you. Please
    feel free to let my manager know what you think of the level of service
    provided. You can send feedback directly to my manager at:
    .

    ==================================================
    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

    Note: MSDN Managed Newsgroup support offering is for non-urgent issues
    where an initial response from the community or a Microsoft Support
    Engineer within 2 business day is acceptable. Please note that each follow
    up response may take approximately 2 business days as the support
    professional working with you may need further investigation to reach the
    most efficient resolution. The offering is not appropriate for situations
    that require urgent, real-time or phone-based interactions. Issues of this
    nature are best handled working with a dedicated Microsoft Support Engineer
    by contacting Microsoft Customer Support Services (CSS) at
    http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
    ==================================================
    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Allen Chen [MSFT], Dec 15, 2008
    #2
    1. Advertising

  3. SAL

    SAL Guest

    Hi Allen,
    I'm e-mailed the repro project to you.. Thanks

    S

    "Allen Chen [MSFT]" <> wrote in message
    news:...
    > Hi SAL,
    >
    > Could you send me that demo project? I'd like to repro it on my side
    > first.
    >
    > My email is . Please update here after sending the
    > project in case I missed that email.
    >
    >
    > Regards,
    > Allen Chen
    > Microsoft Online Support
    >
    > Delighting our customers is our #1 priority. We welcome your comments and
    > suggestions about how we can improve the support we provide to you. Please
    > feel free to let my manager know what you think of the level of service
    > provided. You can send feedback directly to my manager at:
    > .
    >
    > ==================================================
    > Get notification to my posts through email? Please refer to
    > http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.
    >
    > Note: MSDN Managed Newsgroup support offering is for non-urgent issues
    > where an initial response from the community or a Microsoft Support
    > Engineer within 2 business day is acceptable. Please note that each follow
    > up response may take approximately 2 business days as the support
    > professional working with you may need further investigation to reach the
    > most efficient resolution. The offering is not appropriate for situations
    > that require urgent, real-time or phone-based interactions. Issues of this
    > nature are best handled working with a dedicated Microsoft Support
    > Engineer
    > by contacting Microsoft Customer Support Services (CSS) at
    > http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
    > ==================================================
    > This posting is provided "AS IS" with no warranties, and confers no
    > rights.
    >
     
    SAL, Dec 15, 2008
    #3
  4. Hi SAL,

    I've received the project. Thanks.

    I did following test:

    1. Remove the UpdatePanel. This issue can still be reproduced.

    2. I delete your code one by one and finally get a concise demo that can
    reproduce this problem. It turned out it's caused by the use of the
    SessionParameter. If you try step 1 to remove the UpdatePanel and use
    following code instead it works fine:

    <asp:ObjectDataSource ID="dsStormInsert" runat="server"
    DeleteMethod="Delete" EnableViewState="true"
    OldValuesParameterFormatString="original_{0}"
    SelectMethod="GetStormValueByStormValueId"
    TypeName="StormValueBLL"
    UpdateMethod="UpdateStormTable">
    <DeleteParameters>
    <asp:parameter Name="stormValueid" Type="Int32" />
    </DeleteParameters>
    <SelectParameters>
    <asp:parameter Name="id" Type="Int32" />
    <%-- <asp:SessionParameter Name="id"
    SessionField="stormValueId" Type="Int32" />--%>
    </SelectParameters>
    </asp:ObjectDataSource>

    Protected Sub ManageEdit(ByVal rowNumber As Integer)

    Dim svalueId As Integer = gvStormDetail.DataKeys(rowNumber).Value
    If svalueId > 0 Then
    'Session(STORMVALUEID) = svalueId
    dsStormInsert.SelectParameters(0).DefaultValue = svalueId

    dvStormInsert.ChangeMode(DetailsViewMode.Edit)
    Me.ddlAssetType.Enabled = False
    Me.ddlAssetType.SelectedValue = GetStormAssetId(svalueId)
    End If
    End Sub

    Please try it and let me know if it works(If UpdatePanel is added it will
    throw an exception. I need more time to look into your code to see what the
    problem is).

    Regards,
    Allen Chen
    Microsoft Online Support
     
    Allen Chen [MSFT], Dec 16, 2008
    #4
  5. SAL

    SAL Guest

    Hmmm,
    I can see where you changed the code. Having this particular updatepanel is
    a really nice feature we'd like to keep so we don't have to do a complete
    page update.
    I can see where you changed the code from a session parameter to using the
    DefaultValue parameter. Can you please let me know if you find the cause of
    this problem? I also wouldn't mind knowing why the session parameter is
    causing a problem.

    Thanks Allen
    S

    "Allen Chen [MSFT]" <> wrote in message
    news:...
    > Hi SAL,
    >
    > I've received the project. Thanks.
    >
    > I did following test:
    >
    > 1. Remove the UpdatePanel. This issue can still be reproduced.
    >
    > 2. I delete your code one by one and finally get a concise demo that can
    > reproduce this problem. It turned out it's caused by the use of the
    > SessionParameter. If you try step 1 to remove the UpdatePanel and use
    > following code instead it works fine:
    >
    > <asp:ObjectDataSource ID="dsStormInsert" runat="server"
    > DeleteMethod="Delete" EnableViewState="true"
    > OldValuesParameterFormatString="original_{0}"
    > SelectMethod="GetStormValueByStormValueId"
    > TypeName="StormValueBLL"
    > UpdateMethod="UpdateStormTable">
    > <DeleteParameters>
    > <asp:parameter Name="stormValueid" Type="Int32" />
    > </DeleteParameters>
    > <SelectParameters>
    > <asp:parameter Name="id" Type="Int32" />
    > <%-- <asp:SessionParameter Name="id"
    > SessionField="stormValueId" Type="Int32" />--%>
    > </SelectParameters>
    > </asp:ObjectDataSource>
    >
    > Protected Sub ManageEdit(ByVal rowNumber As Integer)
    >
    > Dim svalueId As Integer = gvStormDetail.DataKeys(rowNumber).Value
    > If svalueId > 0 Then
    > 'Session(STORMVALUEID) = svalueId
    > dsStormInsert.SelectParameters(0).DefaultValue = svalueId
    >
    > dvStormInsert.ChangeMode(DetailsViewMode.Edit)
    > Me.ddlAssetType.Enabled = False
    > Me.ddlAssetType.SelectedValue = GetStormAssetId(svalueId)
    > End If
    > End Sub
    >
    > Please try it and let me know if it works(If UpdatePanel is added it will
    > throw an exception. I need more time to look into your code to see what
    > the
    > problem is).
    >
    > Regards,
    > Allen Chen
    > Microsoft Online Support
    >
     
    SAL, Dec 16, 2008
    #5
  6. Hi SAL,

    Thanks for your update. After debugging your code for a while I finally
    found the root cause of this issue. It's caused by disabling the ViewState.

    If ViewState is disabled in the ObjectDataSource control DetailsView will
    be rebound. This happens after the validation control's work. So the
    expected layout of the DetailsView get lost due to the rebinding.

    To solve this problem. You can enable the ViewState of the following two
    controls:

    <asp:UpdatePanel ID="upInsert" runat="server" EnableViewState="true"

    <asp:ObjectDataSource ID="dsStormInsert" runat="server"
    DeleteMethod="Delete" EnableViewState="true"

    It should work.

    Please have a try and let me know if you need further assistance.

    Regards,
    Allen Chen
    Microsoft Online Community Support
     
    Allen Chen [MSFT], Dec 17, 2008
    #6
  7. SAL

    SAL Guest

    Wow, what a simple solution and man I tried everything (I thought)!
    Thanks so much for helping me solve this one Allen, much appreciated

    S
    "Allen Chen [MSFT]" <> wrote in message
    news:KMrz2K$...
    > Hi SAL,
    >
    > Thanks for your update. After debugging your code for a while I finally
    > found the root cause of this issue. It's caused by disabling the
    > ViewState.
    >
    > If ViewState is disabled in the ObjectDataSource control DetailsView will
    > be rebound. This happens after the validation control's work. So the
    > expected layout of the DetailsView get lost due to the rebinding.
    >
    > To solve this problem. You can enable the ViewState of the following two
    > controls:
    >
    > <asp:UpdatePanel ID="upInsert" runat="server" EnableViewState="true"
    >
    > <asp:ObjectDataSource ID="dsStormInsert" runat="server"
    > DeleteMethod="Delete" EnableViewState="true"
    >
    > It should work.
    >
    > Please have a try and let me know if you need further assistance.
    >
    > Regards,
    > Allen Chen
    > Microsoft Online Community Support
    >
     
    SAL, Dec 17, 2008
    #7
  8. Hi SAL,

    You're welcome. Have a nice day!

    Regards,
    Allen Chen
    Microsoft Online Support
     
    Allen Chen [MSFT], Dec 18, 2008
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    4
    Views:
    947
    Richter~9.6
    Feb 13, 2007
  2. Replies:
    3
    Views:
    513
    Rob Meade
    Aug 8, 2007
  3. Nathan Sokalski
    Replies:
    1
    Views:
    616
    miher
    Jun 15, 2009
  4. Nathan Sokalski

    Validator not working when inside UpdatePanel

    Nathan Sokalski, Dec 4, 2009, in forum: ASP .Net
    Replies:
    13
    Views:
    2,080
    Jay Woerndle
    Sep 8, 2010
  5. Nathan Sokalski

    Validator not working when inside UpdatePanel

    Nathan Sokalski, Dec 4, 2009, in forum: ASP .Net Web Controls
    Replies:
    12
    Views:
    1,036
    Nathan Sokalski
    Dec 9, 2009
Loading...

Share This Page