Solved

how to set html textbox/label value in codebehind

Posted on 2006-11-02
4
505 Views
Last Modified: 2008-02-01
I have an html input text that I am trying to set from codebehind. how do I do this?

aspx page:
<input id="CustomerName" value="<%= strCustomerName %>"/>

aspc.cs page:

class...
{
string strCustomerName ="test";

   protected void Page_Load(object sender, EventArgs e)
    {
      try
      {
          strCustomer = "this doesn't work";
.....

I get the "test" but not the "this doesn't work" - I'm guessing a protection level/page scoping problem?

any help would be greatly appreciated....
 
0
Comment
Question by:acdagirl
  • 2
4 Comments
 
LVL 25

Accepted Solution

by:
nauman_ahmed earned 450 total points
ID: 17861387
<input id="CustomerName" runat=server>

from code-behind:

CustomerName.Text = "text";

--Nauman.
0
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 50 total points
ID: 17861390
In order to access is from code-behind you need to add a runat="server" attribute to it. This way the runtime will wrap it as a GenericControl and allow you to set its properties from code-behind as you would with any standard server control.
0
 

Author Comment

by:acdagirl
ID: 17861648
ah, ok, thanks!

I seem to get both the suggestion above working now. But this also works...
class...
    public string strCustomerImpact = "";
 
page_load
           strCustomerImpact = "customer impact";
 
aspx:
 <textarea id="txtCustomerImpact" cols="60" rows = "5"                  
                                   readonly="readonly"><%= strCustomerImpact %></textarea>

If I wanted to send the contents of my aspx page in an email, which method would render properly, or both as they both generate html on running?

thanks!
0
 
LVL 25

Expert Comment

by:nauman_ahmed
ID: 17862072
I recommend using the code-behind approach.

--Nauman.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

770 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