English 中文(简体)
为什么我的形式使背后,那天才有必要的实地有效度?
原标题:Why my form make postback ,althouth there s a required field validtion wasn t matched?

Q:

I have a RequiredFieldValidator on my page ,when i click the button which is (postback triggered) it makes the postback, although the field which is required wasn t entered ! What s the reason to this behavior?

My .aspx:

                       <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                            <Triggers>
                                <asp:PostBackTrigger ControlID="btn_Search" />
                            </Triggers>
                            <ContentTemplate>
                                <asp:ImageButton ID="btn_Search" runat="server" ImageUrl="~/Images/save.png" 
                                    OnClick="btn_Search_Click" OnClientClick="return postbackButtonClick();" />
                            </ContentTemplate>
                        </asp:UpdatePanel>

                     <asp:DropDownList ID="ddl_department" runat="server" Width="200px" OnSelectedIndexChanged="ddl_department_SelectedIndexChanged"
                            AutoPostBack="True">
                        </asp:DropDownList>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="ddl_department"
                            Display="Dynamic" ErrorMessage="*" InitialValue="-1"></asp:RequiredFieldValidator>

                        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                            <ContentTemplate>
                                <asp:DropDownList ID="ddl_study" runat="server" Width="200px">
                                </asp:DropDownList>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="ddl_study"
                                    Display="Dynamic" ErrorMessage="*" InitialValue="-1"></asp:RequiredFieldValidator>
                            </ContentTemplate>
                            <Triggers>
                                <asp:AsyncPostBackTrigger ControlID="ddl_department" EventName="SelectedIndexChanged" />
                            </Triggers>
                        </asp:UpdatePanel>

                        <script type="text/javascript">
                            var updateProgress = null;
                            function postbackButtonClick() {
                                updateProgress = $find("<%= UpdateProgress1.ClientID %>");
                                window.setTimeout("updateProgress.set_visible(true)", updateProgress.get_displayAfter());
                                return true;
                            }
                        </script>
最佳回答

Remove Return Clause from LinkButton srite OnClientClick property Value:OnClientClick=“postbackButtonClick( and rew postButtonClick 如下:

function postbackButtonClick() {
     Page_ClientValidate();

     if (Page_IsValid) {
          updateProgress = $find("<%= UpdateProgress1.ClientID %>");
          window.setTimeout("updateProgress.set_visible(true)", updateProgress.get_displayAfter());
          return true;
     }
}
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签