?
Solved

asp.net c#

Posted on 2007-10-19
7
Medium Priority
?
161 Views
Last Modified: 2013-11-26
I have detailview in a page, and inside of detailview I create templateitem and add textbox and button there...How can I call the value from the textbox?

This is aspx c#
0
Comment
Question by:riskyricky1972
  • 4
6 Comments
 
LVL 16

Expert Comment

by:McExp
ID: 20112930
I'm guessing your trying to access the value from code behind?

If So you can use the helper function at the end of this post to get a reference to the control in the template, just call as follows: -

TextBox myTextBox = FindControl(DetailsView1,"textBoxId");

    /// <summary>
    /// Returns a control if one by that name exists in the hierarchy of the controls collection of the start control
    /// </summary>
    /// <param name="start"></param>
    /// <param name="id"></param>
    /// <returns></returns>
    public static Control FindControl(Control start, string id)
    {
        Control foundControl;

        if (start != null)
        {
            foundControl = start.FindControl(id);

            if (foundControl != null)
                return foundControl;

            foreach (Control c in start.Controls)
            {
                foundControl = FindControl(c, id);
                if (foundControl != null)
                    return foundControl;
            }
        }
        return null;
    }
0
 
LVL 14

Expert Comment

by:Jai S
ID: 20113574
easy way without looops...
when you ASPX page loads,...check the VIEW --> Source from your browser, see the name of the text box that you are adding...it will be norammly a appended string with your details view...just use the name as findControls(thename) which wil lretun the object to you, then box it to a text box like this

textbox txt = (textbox)Findcontrols(the contorlname);
pardon me for an syntax errors in the code
0
 
LVL 16

Expert Comment

by:McExp
ID: 20114197
The soluition suggested by the previous poster will probably fail for two reasons you may find that you cant actulally find the control, see quote from msdn site: -

"The FindControl method can be used to access a control whose ID is not available at design time. The method searches only the page's immediate, or top-level, container; it does not recursively search for controls in naming containers contained on the page. To access controls in a subordinate naming container, call the FindControl method of that container."

and the "Find control" command expects the server ID of the control not the Client ID as suggested.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:riskyricky1972
ID: 20128835
McExp: Can U help?
0
 
LVL 16

Expert Comment

by:McExp
ID: 20157593
Was my first solution not clear enough?

What sort of further guidance are you looking for?
0
 
LVL 16

Accepted Solution

by:
McExp earned 1000 total points
ID: 20282865
Have you resolved your problems?

If so shall we close this off?

We might even win the laptops!!!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
This video tutorial shows you the steps to go through to set up what I believe to be the best email app on the android platform to read Exchange mail.  Get the app on your phone: The first step is to make sure you have the Samsung Email app on your …
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question