Click here to Skip to main content
15,895,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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") %>' />


Now I want validate using javascript on this controls but its not working.

Eg.
var eventStatus=document.getElementById("<%=txtEditEventName.ClientID%>").value;


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 &#39;<%# Eval("event_name")%>&#39;</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>
Posted
Updated 28-Oct-11 3:07am
v2
Comments
Muralikrishna8811 28-Oct-11 6:37am    
when you want to check that textbox on leave focus event or some other control event

post some code for it

and you've to make this javascript validation in databound event or someother
because you are using textbox in datacontrol so

can you post with some code we can solve it
udusat13 28-Oct-11 9:02am    
I want the javascipt validation code on update button.I took one following update button in EditTemplate
<asp:LinkButton ID="LinkButton2" runat="server" Text="Update" CommandName="Update" />
[no name] 28-Oct-11 8:33am    
What do you mean "its not working"? You have to be a little more detailed. What isn't working? Are you not getting the value? Not getting the control?

There is no validation, you are only attempting to get the value.
udusat13 28-Oct-11 8:57am    
var eventStatus=document.getElementById("<%=txtEditEventName.ClientID%>").value;

this line giving me error that txtEditEventName name does not exists.

I am not finding controls within EditTemplate in javascript.

I add javascript code in EditTemplate but still it giving same problem.

1 solution

Hi,

I Here I found one solution for you

check this once
C#
//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 + ")";


And your javascript code contains following code
JavaScript
function f2(tid) {
            var sts = document.getElementById(tid).value;
        }


In sts javascript variable you can get your event textbox value

I hope it helps you

All the Best
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900