Click here to Skip to main content
15,880,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have a formview control which contain textboxs. Im unable to find the control in formview using javascript.My code is

C#
var txtRestaurant = document.getElementById('<%= fvRestaurantMgmt.FindControl("RestaurantNameTextBox").ClientID %>').value;
            var txtCity = document.getElementById('<%= fvRestaurantMgmt.FindControl("CityTextBox").ClientID %>').value;
            var txtState = document.getElementById('<%= fvRestaurantMgmt.FindControl("StateTextBox").ClientID %>').value;
            var txtPostcode = document.getElementById('<%= fvRestaurantMgmt.FindControl("ZipTextBox").ClientID %>').value;
            var txtCountry = document.getElementById('<%= fvRestaurantMgmt.FindControl("CountryTextBox").ClientID %>').value;


I have tried a lot but Im getting error as

MSIL
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.


Can anyone give me a solution.


Thanq
Posted
Updated 12-Jan-11 23:40pm
v2
Comments
Kasson 13-Jan-11 7:42am    
BTW what you wrote in Codebehind?
Sandeep Mewara 13-Jan-11 8:58am    
Error is on server side and not in Javascript. Kindly debug or share the code piece with us.

1 solution

You can do it like this. Add client of your control in one hidden field and then access it like;


C#
<asp:hiddenfield id="hdnNameTextBox" runat="server" xmlns:asp="#unknown" />

    void FormView1_DataBound(object sender, EventArgs e)
    {
      hdnNameTextBox.Value = ((TextBox)FormView1.FindControl("TextBoxId")).ClientID;
    }


Now use the hidden fields value.

Java
var id = document.getElementById('hdnNameTextBox').value;

var txt =  document.getElementById(id);


Anurag
 
Share this answer
 
v2

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