如何從代碼背後的字符串中渲染網頁上的asp.net控件?如何動態呈現控件?
例如,說我有下面的aspx頁面:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="nrm.FRGPproposal.Questionnaire1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
//want to render a text box here
</div>
</form>
</body>
</html>
我可以在我的Page_Load事件做些什麼來呈現一個TextBox到股利?
protected void Page_Load(object sender, EventArgs e)
{
//what do i do here to render a TextBox in the div from the aspx page?
}
正如@Tehrab在下面建議的那樣,最好在較早的生命週期中完成,比如Page Init,而不是頁面加載。 – 2010-06-10 18:12:53
你知道我怎麼可以創建一個新的TextBox對象,就像你從一個像「System.Web.UI.WebControls.TextBox」這樣的字符串做的? – 2010-06-10 18:41:26
你是說你想能夠添加一個文本框合併到div中的一些字符串的中間?就像說你有字符串「輸入名稱[System.Web.UI.WebControls.TextBox]」,你想「[System.Web.UI.WebControls.TextBox]」呈現爲一個TextBox控件? – 2010-06-10 18:58:34