Solved

how to set html textbox/label value in codebehind

Posted on 2006-11-02
4
510 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …

738 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