views:

416

answers:

1

I have put update panel in detailsview insert template, in which put 2 controls(textbox and dropdown) and a button and on click of button, I have clear the textbox and clear seletion of dropdown, validator automatically on after postback, this should not be? Have any one solution of this problem? If I not use detials and put these controls and on simple page, this work perfect.

Plz Look at source code, I have make an example to clear the situation

<asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="225px" DefaultMode="Insert"
        DataSourceID="ods">
        <Fields>
            <asp:TemplateField HeaderText="testing" Visible="true">
                <InsertItemTemplate>
                    <asp:UpdatePanel runat="server" ID="upnl">
                        <ContentTemplate>
                            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="TextBox1"
                                runat="server" ErrorMessage="*"></asp:RequiredFieldValidator>
                            <br />
                            <asp:DropDownList ID="ddlResourceAdd" runat="server" Width="150px">
                                <asp:ListItem Text="--- Please Select ---" Value="-1" Selected="True"> </asp:ListItem>
                                <asp:ListItem Text="abc" Value="1"> </asp:ListItem>
                                <asp:ListItem Text="Def" Value="1"> </asp:ListItem>
                            </asp:DropDownList>
                            <asp:CompareValidator ID="cmvResourceAdd" runat="server" ControlToValidate="ddlResourceAdd"
                                ErrorMessage="*" Operator="NotEqual" SetFocusOnError="True" ValueToCompare="-1"></asp:CompareValidator>
                            <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
                        </ContentTemplate>
                    </asp:UpdatePanel>
                </InsertItemTemplate>
            </asp:TemplateField>
        </Fields>
    </asp:DetailsView>
    <asp:ObjectDataSource ID="ods" runat="server" DeleteMethod="DeleteEmpByEmpID" InsertMethod="AddEmp"
        SelectMethod="GetEmp" TypeName="RisingTech.Core.BLL.Emp" UpdateMethod="ModifyEmp">
                  <UpdateParameters>
           <asp:Parameter Name="fullName" Type="String" />
        </UpdateParameters>
        <SelectParameters>
        </SelectParameters>
        <InsertParameters>
           <asp:Parameter Name="fullName" Type="String" />
        </InsertParameters>
    </asp:ObjectDataSource>

Code in codebehind

protected void Button1_Click(object sender, EventArgs e)
{
    TextBox1.Text = "";
    ddlResourceAdd.SelectedValue = "-1";
}
A: 

I use the trick and solve this problem. I have just disable the validator.

protected void Button1_Click(object sender, EventArgs e)
{
    TextBox1.Text = "";
    ddlResourceAdd.SelectedValue = "-1";
    rfv.Enabled = false;
    cmvResourceAdd.Enabled = false;
}

On the client click, I enable these validators again.

    function test() {
        ValidatorEnable(document.getElementById('<%=rfv.ClientID%>'), true);
        ValidatorEnable(document.getElementById('<%=cmvResourceAdd.ClientID%>'), true);
    }
Muhammad Akhtar