Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how to set html textbox/label value in codebehind

Posted on 2006-11-02
4
Medium Priority
?
516 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 1800 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 200 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

877 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