Monday, March 26, 2012

Pass Value from Code Behind to TextBox

Hi, I have a very basic question (I am a beginner)

How do I pass a value from the Code Behind to, say, a text box?

I've got this on my aspx page:

<asp:TextBoxID="TextBox1"runat="server"Text=strTestOnTextChanged="TextBox1_TextChanged"></asp:TextBox>

All I want to do is pass the value of strTest from the Code Behind to display in the Text Box. This is what I have in the code behind:

using System;

using System.Data;

using System.Configuration;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

publicpartialclass_Default : System.Web.UI.Page

{

protectedvoid Page_Load(object sender,EventArgs e)

{

String strText;strText ="Hello";

}

}

How can I get this to work?

It's very simple just try this

protectedvoid Page_Load(object sender,EventArgs e)

{

String strText;strText ="Hello";

TextBox1.Text =strText;

}


You are right...it is very simple;

Thanks for the help...and Iapologize for the very basic question;


don't forget to mark as answerd the post if it is.

Greets


Whenever you write something in PageLoad event, it should be executed with every postback event... So use IsPostBack event of page to identify page was post back or not ...

0 comments:

Post a Comment