C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » ASP.NET/Web Applications »

Referencing Controls in Templates after mode changes in Formview


Posted Date: 09 Apr 2008    Resource Type: Articles    Category: ASP.NET/Web Applications
Author: JohnPrasad PanthadiMember Level: Silver    
Rating: 1 out of 5Points: 5



Controls of a template are created dynamically when the template is shown, trying to get a reference to these controls in the typical way will lead to a null reference exception.

Thus, the way to get a reference to a control in a template is using the FindControl method, which looks for controls within the current naming container by its Id

Now suppose that you want to update some controls when the user switches from one FormViewMode to another. For example, you may want to get a DropDownList filled with data when entering Edit mode. At first you may think that handling the ModeChanged event of the FormView is the correct solution.

Sub EmployeeFormView_DataBound(ByVal sender As Object, ByVal e As EventArgs)
If myFormView.CurrentMode = FormViewMode.Edit Then
Dim countries As DropDownList = CType(myFormView.FindControl("countriesDropDownList"), DropDownList)
If countries IsNot Nothing Then
' fill the dropdownlist with data
End If
End If
End Sub




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Templates  .  Controls  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: LINQ Introduction
Previous Resource: Client Side State Management Using Cookies
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET/Web Applications


Post resources and earn money!
 
Related Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use