Solved

how to set html textbox/label value in codebehind

Posted on 2006-11-02
4
511 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

687 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