mptyDataTemplate控件上的JavaScript验证

mptyDataTemplate控件上的JavaScript验证

本文介绍了GridView EmptyDataTemplate控件上的JavaScript验证问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

pt
大家好,

目前,我在验证来自gridview emptydatatemplate的用户输入时遇到问题.我将在下面详细说明我的情况.
要求就像用户应该输入数据,并且应该能够在最终保存之前看到输入的数据.因此,我采用了gridview并将其绑定到一个临时表,该临时表最初将没有任何数据,因此在第一页加载时,数据源将为空,并且emptydatatemplate将显示给用户.在此EmptyDataTemplate上,我准备了一个数据输入屏幕,用户可以在其中输入信息并保存数据.保存数据后,数据将转到临时表,并且gridview将使用用户输入的数据填充.接下来,用户可以通过gridview页脚行输入记录.这样我就可以做我的事情.
现在我还没有完成验证,我想对gridview emptydatatemplate和gridview页脚上的用户输入进行验证.为此,我在RowDataBound上创建了一个Button对象,并为其分配了gridview emptydatatemplate保存按钮,并使用此按钮将一个javascript函数绑定在一起,如下所示.

pt
Hi All,

Currently I''m facing a problem validating the user input from gridview emptydatatemplate. I''ll elaborate my scenario below please take a look.
The requirement is like the users should enter data and should be able to see the entered data before final save. So, I''ve taken a gridview and binded it to a temptable which will don''t have any data initially, so on the first page load the datasource will be empty and the emptydatatemplate will be shown to the user. On this EmptyDataTemplate I''ve prepared a dataentry screen where the user can give the information and can save the data. After saving the data the data will go to the temptable and the gridview will get populated with the data the user has entered. For next go, the user can enter records through the gridview footer row. In this way I''m doing my things.
Now I haven''t done the validation yet, I wanted to do a validation of the user input on gridview emptydatatemplate and gridview footer as well. In order to do that I''ve created one Button object on RowDataBound and assigned the gridview emptydatatemplate save button against it and also binded one javascript function with this button like below.

<br />
protected void gvProductData_OnRowDataBound(object sender, GridViewRowEventArgs e)<br />
    {<br />
        Button btnAddModel;<br />
        btnAddModel = (Button)gvProductData.Controls[0].Controls[0].FindControl("btnOk"); // This is the save button of empty data template<br />
        DropDownList ddlModelNoEdt = gvProductData.Controls[0].Controls[0].FindControl("ddlModelNoEDT") as DropDownList;<br />
        DropDownList ddlElectroluxPncSku = gvProductData.Controls[0].Controls[0].FindControl("ddlPncEdt") as DropDownList;<br />
        DropDownList ddlBrandName = gvProductData.Controls[0].Controls[0].FindControl("ddlBrandNameEdt") as DropDownList;<br />
        DropDownList ddlSalesMarketEdt = gvProductData.Controls[0].Controls[0].FindControl("ddlSalesMarketEdt") as DropDownList;<br />
        DropDownList ddlProjectClosedEdt = gvProductData.Controls[0].Controls[0].FindControl("ddlProjectClosedEdt") as DropDownList;<br />
        TextBox txtModelNoEdt = gvProductData.Controls[0].Controls[0].FindControl("txtModelNoEDT") as TextBox;<br />
        TextBox txtPilotRunDate1Edt = gvProductData.Controls[0].Controls[0].FindControl("txtPilotRunDate1Edt") as TextBox;<br />
        TextBox txtPilotRunDate2Edt = gvProductData.Controls[0].Controls[0].FindControl("txtPilotRunDate2Edt") as TextBox;<br />
        TextBox txtMassProdRunDateEdt = gvProductData.Controls[0].Controls[0].FindControl("txtMassProdRunDateInsertEdt") as TextBox;<br />
        TextBox txtShiplogDateEdt = gvProductData.Controls[0].Controls[0].FindControl("txtShiplogDateEdt") as TextBox;<br />
        btnAddModel.Attributes.Add("onClick", "javascript:return validatemodel(''" + ddlModelNoEdt.ClientID + "'',''" + ddlPncSku.ClientID + "'',''" + ddlBrandName.ClientID + "'',''" + txtModelNoEdt.ClientID + "'',''" + ddlSalesMarketEdt.ClientID + "'',''"<br />
            + txtPilotRunDate1Edt.ClientID + "'',''" + txtPilotRunDate2Edt.ClientID + "'',''" + txtMassProdRunDateEdt.ClientID + "'',''" + txtShiplogDateEdt.ClientID + "'',''" + ddlProjectClosedEdt.ClientID + "'');");//Called the javascript function<br />



javascript工作正常,并根据完成的验证返回布尔值.
但是问题是在我执行了此验证之后,gridview的RowCommand事件没有触发.我仅基于按钮的命令名在此事件上插入此记录.但是,如果我删除此javascript验证,那么一切对我来说都很好.
我正在使用.NET3.5,Visual Studio2008.我的gridview位于ajax tabcontainer内.有什么办法可以使用javascript验证Gridview EmptyDataTemplate和Footer Template上的用户输入.在此方面的任何帮助将不胜感激.预先感谢.



The javascript is working fine and returning boolean values based on the validation done.
But the problem is after I did this validations the RowCommand event of my gridview is not firing. I''m inserting this records on this event only based on the commandname of the button. But if I remove this javascript validation everything works fine for me.
I''m using .NET3.5, Visual Studio 2008. My gridview resides inside an ajax tabcontainer. Is there any way I can validate the user input on Gridview EmptyDataTemplate and Footer Template using javascript. ANy help on this would be highly appreciated. Thanks in advance.

推荐答案

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ZTest.aspx.cs" Inherits="ZTest" EnableEventValidation="false" %>


2.为btnOk创建事件


2.Create event for btnOk

protected void btnOk_Click(object sender, EventArgs e)
    {
        //Your code for saving data into DataBase is here...
    }


3.将点击事件附加到客户端的btnOk


3. Attach click event to the btnOk at client side

<asp:Button ID="btnOk" runat="server" CausesValidation="true" CssClass="button-go"Text="Add Model" Width="80" OnClick="btnOk_Click" />




如有任何疑问,请让我知道.

如果有帮助,请提供"投票",如果这是正确的答案,请提供"接受答案".

谢谢,
Imdadhusen




Please do let me know, if you have any doubt.

Please provide "Vote" if this would be helpful, and make "Accept Answer" if this would be correct answer.

Thanks,
Imdadhusen


这篇关于GridView EmptyDataTemplate控件上的JavaScript验证问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 04:33