Solved

Textbox Value

Posted on 2012-04-01
13
322 Views
Last Modified: 2012-08-14
Hello:

I am trying to show a value in a textbox that I got from a database table. I know the data is pulling the values correctly. Here is my textbox:

<asp:TextBox ID="NameText" Text="<%# adjName %>" runat="server" Width="200px" />

Dan
0
Comment
Question by:RecipeDan
  • 4
  • 3
  • 3
  • +2
13 Comments
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
Unfortunately, that is not enough markup to go on. We would need to see what container you are using (e.g. Repeater, GridView, etc.) in order to give you proper syntax to databind with. Can you elaborate?
0
 
LVL 38

Expert Comment

by:Tom Beck
Comment Utility
If adjName is a server side variable with the value you want to assign, then it must be declared public in your server code in order to acces it with <%# adjName %> in aspx page.

        public string adjName;
0
 
LVL 1

Author Comment

by:RecipeDan
Comment Utility
OK hereis my whole aspx:

 <ajaxToolkit:TabContainer ID="ProfileContainer" TabStripPlacement="Top" runat="server" Width="650" BorderColor="Black" ActiveTabIndex="0">
<ajaxToolkit:TabPanel runat="server" HeaderText="Header1" ID="Tab1">
        <ContentTemplate>
            <table cellpadding="3" style="width: 558px">
            <tr>
            <td><asp:Label runat="server" CssClass="RequiredLabelClass" Text="Name:" ID="NameLabel" /></td>
            <td><<asp:TextBox ID="NameText" Text="<%# adjName %>" runat="server" Width="200px" /></td>
            </tr>

            </table>
        </ContentTemplate>

        </ajaxToolkit:TabPanel>
       
        <ajaxToolkit:TabPanel runat="server" HeaderText="Header2" ID="Tab2">
           
        </ajaxToolkit:TabPanel>
   
    </ajaxToolkit:TabContainer>
0
 
LVL 21

Expert Comment

by:masterpass
Comment Utility
so adjName is a varibale in the server side ? If yes, like tommyboy said .. make it public and then try accessing it like this

Text="<%= adjName %>"
0
 
LVL 5

Expert Comment

by:Rainverse
Comment Utility
What he said ^^.  Replace the # with an =.  <%= adjName %>

-MJC
0
 
LVL 74

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 150 total points
Comment Utility
Respone.Write sytnax ( <%= ... %> ) does not work within properties of server controls (AFAIK). Data-binding syntax ( <%# ... %> ) would be the proper way of making a property bound to some backing data store.

Please let us know where the data is coming from. I don't see where you have connected your ajaxToolkit:TabContainer to a data source.
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 38

Assisted Solution

by:Tom Beck
Tom Beck earned 200 total points
Comment Utility
Assuming it's a publicly declared server variable, it would have to be done using javascript.

<body>
    <form runat="server" id="form1">
         <asp:TextBox ID="NameText" runat="server" Width="200px" />
    </form>
    <script type="text/javascript">        
         document.getElementById("NameText").value = "<%= adjName %>";
    </script>
</body>
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
Assuming it's a publicly declared server variable, it would have to be done using javascript.
What about code-behind?  ; )
0
 
LVL 38

Expert Comment

by:Tom Beck
Comment Utility
You're right, it would be kind of pointless.
0
 
LVL 1

Author Comment

by:RecipeDan
Comment Utility
Hello:

The tab container itself is not connected to a datasource. I have a form in the tab container that I want to get values from a database. The values are pulling from he database because I tested it with asp:label and the values show. I can't get the values to show in the textbox.
0
 
LVL 21

Assisted Solution

by:masterpass
masterpass earned 150 total points
Comment Utility
Try like this
TextBox nameTxt = (TextBox) ProfileContainer.FindControl("Tab1").FindControl("NameText");
nameTxt.text = "value from database";

Open in new window

Hope this helps!
0
 
LVL 1

Accepted Solution

by:
RecipeDan earned 0 total points
Comment Utility
I figured it out. This works:

<asp:TextBox ID="NameText" runat="server" Width="200px" />

NameText.Text = Convert.ToString(reader["UserName"]);
0
 
LVL 1

Author Closing Comment

by:RecipeDan
Comment Utility
See Comment. I figured it out on my own.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now