Link to home
Start Free TrialLog in
Avatar of rgagli1
rgagli1

asked on

Refresh the value of a textbox once a user updates the DetailsView in Wizard

I'm using the wizard and created a contact page.  On this page there is a DetailsView that pulls all the current information from a database.  If the user clicks edit and updates their contact information everything looks great in the DetailsView but there's a textbox in a FormView (on the same page) that keeps the old value.  This is causing a problem because I added this form view to ensure the email address is entered.  For all users the email address is blank and it was the only way I could ensure a user types in the email address.  Now if the user gets the error, then clicks Edit and adds the email address, I still get the same error.  I know its because the value of that textbox was not updated when a user clicked Update in the DetailsView.  Is there a way to update the values in the textbox after a user presses update?
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

I am confused why you aren't using something like a RequiredFieldValidator?

Bob
Avatar of rgagli1
rgagli1

ASKER

Its a Detailsview so when the page first loads its only in the item view only state so the email address is blank.  If the user clicks edit, I have a RequiredFieldValidator present and it forces them to enter it.  But if they don't press edit and click Next it doesn't stop them.  I tried adding it to the Itemtemplate but couldn't get it to work.  So I thought maybe if I use a formview and put the email address in that...it will stop them.  It does stop them and tells them to Press Edit and enter an email address....but the hidden formview doesn't update and is still blank so they can't continue.  Does this make any sense?  
No, not even close.  Can you attach a screen shot of the page to show me what you mean?

Bob
Avatar of rgagli1

ASKER

Here are some screenshots.  I want to ensure the email address is present.  Since the DetailsView loads, the user can hit Next and it will not validate the email address is present.  I added the formview to validate this and it works but I can't get it to update once the user enters an email address.  Any suggestions?
Screen-shots.doc
Avatar of rgagli1

ASKER

I've even tried databind() this is in the vb code.  If I already have an email address in the detailsview, I can't get the textbox at the top to update once I've updated the record.

My code and a screenshot are below:
    Sub DetailView1_ItemUpdated(ByVal sender As Object, _
       ByVal e As DetailsViewUpdatedEventArgs)
        Dim formview4 As FormView
        formview4 = CType(Contact.ContentTemplateContainer.FindControl("formview4"), FormView)
 
        formview4.databind()
    End Sub
 
    Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim formview4 As FormView
        formview4 = CType(Contact.ContentTemplateContainer.FindControl("formview4"), FormView)
 
        formview4.DataBind()
    End Sub

Open in new window

OutofSync.doc
Avatar of rgagli1

ASKER

This is odd.  If an email address is present, the formview updates properly.  I'm only getting this error when there is no email address present.  So it validates correctly and says go enter an email address.  But once they click edit, the formview will not update to add the email address.  

Here is a screenshot of the page with an email address present...you will notice that it does update after the user clicks update.
Editing-the-screenshot.doc
Is the problem with a blank email in the DetailsView or the TextBox below the DetailsView?

Bob
Avatar of rgagli1

ASKER

The textbox in the formview reads the email address (from the same datasource as the detailsview).  It was the only way I could figure out how to validate the textbox since the requiredfieldvalidtor only catches the blank email when the user clicks edit.  I can get the textbox in the formview to update if there is already an email address present.  However, if the email address is blank it tells the user to click Edit and add an email address.  If they then hit update, they still get the error that the email address is blank (this is because the textbox in the formview) was not updated.  This was the work around I made for this....I only want to ensure the email address is present before the user can continue.
Here is an example of what I would do with a RequiredFieldValidator and handling the NextButtonClick event:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Wizard.aspx.vb" Inherits="Wizard" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    <style type="text/css">
    body { font-family: tahoma; font-size: small; }
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:Wizard ID="Wizard1" runat="server" Style="z-index: 100; left: 24px; position: absolute;
                top: 16px" ActiveStepIndex="1" Height="328px" Width="664px">
                <WizardSteps>
                    <asp:WizardStep ID="WizardStep1" runat="server" Title="Terms of Use">
                        <asp:Label runat="server" ID="terms" Text="Terms" />
                    </asp:WizardStep>
                    <asp:WizardStep ID="WizardStep2" runat="server" Title="Contact Information">
                        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TestConnectionString %>" ProviderName="<%$ ConnectionStrings:TestConnectionString.ProviderName %>" SelectCommand="SELECT id, name, Email FROM Table1 WHERE (id = @id)">
                            <SelectParameters>
                                <asp:QueryStringParameter DefaultValue="1" Name="id" QueryStringField="id" />
                            </SelectParameters>
                        </asp:SqlDataSource>
                        <asp:DetailsView ID="DetailsView1" runat="server" Width="100%" AutoGenerateRows="False"
                            AutoGenerateEditButton="True" DataSourceID="SqlDataSource1">
                            <Fields>
                                <asp:BoundField DataField="Name" HeaderText="Name" />
                                <asp:TemplateField HeaderText="E-Mail">
                                    <HeaderStyle Width="50px" />
                                    <ItemTemplate>
                                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Email") %>' Width="90%"
                                            ReadOnly="true" />
                                        <asp:RequiredFieldValidator runat="server" ID="RequiredEmail1" ControlToValidate="TextBox1"
                                            Text="*" />
                                    </ItemTemplate>
                                    <EditItemTemplate>
                                        <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Email") %>' Width="90%"
                                            BackColor="LemonChiffon" />
                                        <asp:RequiredFieldValidator runat="server" ID="RequiredEmail2" ControlToValidate="TextBox2"
                                            Text="**" />
                                    </EditItemTemplate>
                                    <InsertItemTemplate>
                                        <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Email") %>' Width="90%" BackColor="LightCyan"  />
                                        <asp:RequiredFieldValidator runat="server" ID="RequiredEmail3" ControlToValidate="TextBox3"
                                            Text="***" />
                                    </InsertItemTemplate>
                                </asp:TemplateField>
                            </Fields>
                        </asp:DetailsView>
                        <asp:ValidationSummary ID="ValidationSummary1" runat="server" Width="100%" />
                    </asp:WizardStep>
                    <asp:WizardStep ID="WizardStep3" runat="server" Title="Confirmation">
                    </asp:WizardStep>
                </WizardSteps>
                <SideBarStyle BackColor="SteelBlue" ForeColor="White" VerticalAlign="Top" Width="150px" />
                <SideBarButtonStyle ForeColor="White" />
                <StepNextButtonStyle Font-Names="Tahoma" />
                <StepStyle VerticalAlign="Top" />
                <NavigationButtonStyle Font-Names="Tahoma" />
            </asp:Wizard>
        </div>
    </form>
</body>
</html>


Imports System.Data
 
Partial Class Wizard
  Inherits System.Web.UI.Page
 
  Protected Sub Wizard1_NextButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs) Handles Wizard1.NextButtonClick
    e.Cancel = e.CurrentStepIndex = 1 AndAlso Not Page.IsValid
  End Sub
 
End Class

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rgagli1

ASKER

Thank you!