Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code embedded in aspx page

Status
Not open for further replies.

developer155

Programmer
Jan 21, 2004
512
US
Hi,
I am having a difficuly understanding when the code that is embedded into aspx page itself (NOT code behind file) is executed. I am talking about the inline code and when it is executed comparing to other page life cycle events such as Page Load, PreRender, Render, etc

What I am trying to do (without success) is to dynamically crerate a control and add it to a placeholder all from a function called from inline code <%AddDynamicControl();%>

The reason I am not doing this from code behind is because the dynamic control needs string that is created when another inline function is called

thanks
 
example of dynamically adding a control
aspx
Code:
...
<body>
   <form ...>
     <asp:PlaceHolder ID="myPlaceHolder" />
   </form>
</body>
...
code behind
Code:
protected void Page_Init(object sender, EventArgs e)
{
    //note: Don't check for postback!
    TextBox txtBox = new TextBox();
    txtBox.ID = "myTextBox";
    this.myPlaceHolder.Controls.Add(txtBox);
}

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        TextBox txtBox = (TextBox)this.myPlaceHolder.FindControl("myTextBox");
        txtBox.Text = "Text goes Here.";

    }        
}

//if you want to alter the HTML output of the control do this in the PreRender event.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top