FormView FindControl Item

Hi Experts!
I use .net 3.5 vb; This project is using an Object Data Source (SQL 2005) DataTable Adapter...

Could someone please show how an accurate Sub would look for setting a cookie based on the value of a FormView Item DataBound Label?

My aspx has lblCustomerName the ID and Text as (eval) "CustomerName"... It pulls the data fine from a preceding page, I just have not found the correct code to set that Eval "CustomerName" as the cookie Value...
ncrockerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
Context...we need context...where and when do you need this value?  Do you need this on the page load?
0
ncrockerAuthor Commented:
I'm sorry; I am attaching Code Snippets.
It does not need to be in the PageLoad (I don't think?) I need to send it as a cookie to populate an Aspose.Words Document...
And the problem seems to be actually setting it. I'm assuming I need to call it as the FormView Control (Label) that it is and then convert to string for the cookie; or not, since the item controls are already a string value?

 <asp:FormView ID="fvCustomer" runat="server" DataKeyNames="customerID" DataSourceID="odsCustomerLetter">
                        <ItemTemplate>
                        <table border="0" id="customerTable" cellpadding="3" cellspacing="0" width="100%">
                         <tr>
                         <td colspan="2">
                          TO: <asp:Label ID="CustomerID" runat="server" 
                                    Text='<%# Eval("customerID") %>' Visible="False" />
                             
                        </td>
                    </tr>
                   <tr>   
                               <td colspan="2">
                               <asp:Label ID="lblCustomerName" runat="server" 
                                    Text='<%# Bind("CustomerName") %>' />
                               </td>
                               </tr>




 Private Sub SetCookies()
        Dim CustomerCookies As HttpCookie = Response.Cookies("CustomerCookies")
        
        Response.Cookies("CustomerCookies")("lblCustomerName") = Convert.ToString("CustomerName")


    End Sub


 Private Sub PopulateCustomerLetter(ByRef asposeDoc As Aspose.Words.Document)
        Dim licAsposeWord As New Aspose.Words.License

       
        If Convert.ToString(Request.Cookies("CustomerCookies")("CustomerMailCode")) <> "" Then
            asposeDoc.Range.FormFields("lblCustomerName").SetTextInputValue(Convert.ToString(Request.Cookies("CustomerCookies")("CustomerName")))
           

        End If

    End Sub

Open in new window

0
Bob LearnedCommented:
If you need to get a value for a label, you can use the FindControl like this:

    Dim lblCustomerName As Label = TryCast(fvCustomer.Row.FindControl("lblCustomerName"), Label)
    If lblCustomerName IsNot Nothing Then
        Dim customerName As String = lblCustomerName.Text
    End If
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

guru_samiCommented:
Protected Sub fvCustomer_DataBound(ByVal sender As Object, ByVal e As EventArgs) Handles fvCustomer.DataBound
        Dim lbl As Label = CType(FormView1.FindControl("lblCustomerName"),Label)
        If (Not (lbl) Is Nothing) Then
            SetCookies(lbl.Text)
        End If
    End Sub

Private Sub SetCookies(ByVal customername As String)
        Dim CustomerCookies As HttpCookie = Response.Cookies("CustomerCookies")
       
        Response.Cookies("CustomerCookies")("lblCustomerName") = customername


    End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ncrockerAuthor Commented:
Yay!!! Thank you EVER SO MUCH!!!!!!!
You just made my day....
0
ncrockerAuthor Commented:

Sorry, I need to "clarify" on the solution...
Because (and I will open another question for points if you'd like)... While your code technically worked... I cannot get multiple variables added..
You had: Private Sub SetCookies(ByVal customername As String)
Which would be swell if I only had to call that one label..
I modified the code to:
Private Sub SetCookies(ByVal sender As Object)
Dim lblCustomerName As String
Dim lblCustomerPhone As String
    Response.Cookies("CustomerCookies")("lblCustomerName") = customername
  Response.Cookies("CustomerCookies")("lblCustomerPhone") = customerPhone
 
End Sub  
But get "Warning" that there is an unused local variable. Now I know this is just a warning, however, my document will not populate... I've tried "Try and Catch" still doesn't work.
Can you help again and/or let me know if you want me to post it as a new question?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.