【问题标题】:ASP: button to input submitASP:输入提交按钮
【发布时间】:2011-02-07 06:54:31
【问题描述】:

我正在尝试使用 literalcontrol 添加一个按钮作为输入 type="submit"

litLevelList.Text += string.Format(" &lt input type='submit' id='{0}' value='{1}' name='{2}' >", btnSave.ClientID, Lang.Trans("Save Changes " )  , btnSave. ??);

我可以使用 CLientID 获取按钮 ID,但如果没有名称,数据似乎不会被提交。

谁能告诉我如何访问 ASP 为按钮控件呈现的名称值。

谢谢, 毗湿奴

【问题讨论】:

  • asp:Button 有什么问题?

标签: asp.net button form-submit clientid


【解决方案1】:

如果您确实必须构建控件,请尝试使用 HtmlGenericControl 或 PlaceHolder 控件

http://msdn.microsoft.com/en-us/library/system.web.ui.htmlcontrols.htmlgenericcontrol.aspx

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.placeholder.aspx

更新

这对我有用:

    LiteralControl txtText = new LiteralControl();
    txtText.Text = "Something";
txtText.Text += "<input type='submit' text='Okay' id='" + btnSave.ClientID + "' name='" + btnSave.UniqueID + "'>"; 
    PlaceHolder1.Controls.Add(txtText);

【讨论】:

  • 这个要求很奇怪。我需要在文字控件中放置一个按钮。由于我无法向文字控件添加按钮,因此我必须手动键入按钮的呈现内容(如果有意义的话)。