Solved

how to set html textbox/label value in codebehind

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

744 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

13 Experts available now in Live!

Get 1:1 Help Now