如何使用JavaScript验证EditTemplate控件? [英] How to use javascript for validating EditTemplate controls?
问题描述
专家,
我正在使用listview EditTemplate编辑事件.
在我的EditTemplate中,有类似..
的控件
Hi Expert,
I am editing events using listview EditTemplate.
In my EditTemplate there are controls like..
<asp:TextBox ID="txtEditEventName" runat="server"
Text=''<%# Bind("event_name") %>'' />
现在,我想在此控件上使用javascript进行验证,但无法正常工作.
例如
Now I want validate using javascript on this controls but its not working.
Eg.
var eventStatus=document.getElementById("<%=txtEditEventName.ClientID%>").value;
而且我没有使用验证控件.
请帮助我如何使用javascript在EditTemplate控件上进行验证?
我的EditTemplate就像下面的
And i am not using validation controls.
Please help me how to use javascript for validation on EditTemplate Controls?
My EditTemplate is like following
<EditItemTemplate>
<td class="command"><asp:LinkButton ID="btnCancel" runat="server" Text="Cancel" CommandName="Cancel" />
<asp:LinkButton ID="LinkButton2" runat="server" Text="Update" CommandName="Update" />
</td>
<div class="header">View Details for '<%# Eval("event_name")%>'</div>
<tr>
<td class="edit" colspan="6" >
<div class="details">
<table class="detailview" cellpadding="0" cellspacing="0">
<tr>
<td>Event Name:</td>
<td>
<asp:TextBox ID="txtEditEventName" runat="server"
Text=''<%# Bind("event_name") %>'' />
</td>
<td>VenueAddress :</td>
<td>
<asp:TextBox ID="txtEditVenue" runat="server" Text=''<%# Bind("venue") %>'' />
</td>
</tr>
<tr>
<td>Country :</td>
<td>
<asp:DropDownList ID="lstEditCountry" runat="server"
Width="174" />
</td>
<td>Event Status:</td>
<td>
<asp:DropDownList ID="lstEditStatus" runat="server" Width="175px" >
<asp:ListItem value=''0'' Selected="True">-Select-</asp:ListItem>
<asp:ListItem >In-Progress</asp:ListItem>
<asp:ListItem >Completed</asp:ListItem>
<asp:ListItem >Aborted</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>Category :</td>
<td>
<asp:DropDownList ID="lstEditCategory" runat="server"
Width="174" />
</td>
</tr>
<tr>
<td>Start Date:</td>
<td>
<asp:TextBox ID="txtEditStartDate" runat="server"
Text=''<%# Bind("start_date", "{0:dd/MM/yyyy}") %>'' />
</td>
<td>End Date:</td>
<td>
<asp:TextBox ID="txtEditEndDate" runat="server"
Text=''<%# Bind("end_date","{0:dd/MM/yyyy}") %>'' />
</td>
</tr>
</table>
<div class="footer command">
<asp:LinkButton ID="LinkButton1" runat="server" Text="Close" CommandName="Cancel" />
</div>
</div>
</td>
</tr>
</EditItemTemplate>
推荐答案
我在这里为您找到了一个解决方案
一次检查一次
Hi,
I Here I found one solution for you
check this once
//Under ListView1_ItemEditing(Object sender, ListViewEditEventArgs e)
ListViewItem item = ListView1 .Items[e.NewEditIndex];
((LinkButton)item.FindControl("LinkButton2")).OnClientClick = "f2(" + ((TextBox)e.Item.FindControl("txtEditEventName")).ClientID + ")";
而且您的javascript代码包含以下代码
And your javascript code contains following code
function f2(tid) {
var sts = document.getElementById(tid).value;
}
在sts javascript变量中,您可以获取事件文本框的值
希望对您有帮助
最好的
In sts javascript variable you can get your event textbox value
I hope it helps you
All the Best
这篇关于如何使用JavaScript验证EditTemplate控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!