RadioButton rb; Label lb;如何將編程創建的標籤的文本分配給html正文中的其他標籤?
while (reader.Read())
{
rb = new RadioButton(); **//radio buttuns created**
lb = new Label(); **// labels created**
lb.Text = reader[0].ToString(); *// each label's text assigned*
rb.Attributes.Add("OnClick", "getSelectedAuthor('"+lb.Text.ToString()+"')");
PlaceHolder1.Controls.Add(rb); *//when the radio clicked,function called*
PlaceHolder1.Controls.Add(lb); *// to set use the text of label*
PlaceHolder1.Controls.Add(new LiteralControl("<br />"));
}
conAuthorTbl.Close();
// innerthtml不爲宗旨的工作,// becuse我需要// Labe2的文本發送到其他頁面,//當我使用Response.Redirect(..),//有沒有字符串來//從Label2的
<script language="javascript" type="text/javascript">
function getSelectedAuthor(text) {
document.getElementById("Label2").innerText = text;
}
</script>
//這裏我想設置文本
<div>
<asp:Label ID="Label2" runat="server" Text="" ></asp:Label>
</div>
你的問題離開很多想象力。如果您使用的是Response.Redirect,那麼您可以將RadioButton的值附加到QueryString以在重定向頁面上使用。 – aaroncatlin 2012-03-06 12:59:02
您必須從服務器端而不是客戶端設置標籤文本屬性。 – arunes 2012-03-06 13:00:02
我正確使用了Response.Reditect,但它不起作用。問題是沒有任何字符串屬於Label2 – user1214973 2012-03-06 13:03:05