[英]Formatting Controls in ASP.NET
我覺得這似乎是一個簡單的問題,但是在任何地方都找不到答案。 我們有一個接口,試圖將其移至ASP.NET控件。 當前看起來像:
<link rel=""stylesheet"" type=""text/css"" href=""/Layout/CaptchaLayout.css"" />
<script type=""text/javascript"" src=""../../Scripts/vcaptcha_control.js""></script>
<div id="captcha_background">
<div id="captcha_loading_area">
<img id="captcha" src="#" alt="" />
</div>
<div id="vcaptcha_entry_container">
<input id="captcha_answer" type="text"/>
<input id="captcha_challenge" type="hidden"/>
<input id="captcha_publickey" type="hidden"/>
<input id="captcha_host" type="hidden"/>
</div>
<div id="captcha_logo_container"></div>
</div>
但是,我看到的所有允許基本功能的ASP.NET控件示例-即
public class MyControl : Panel
{
public MyControl()
{
}
protected override void OnInit(EventArgs e)
{
ScriptManager.RegisterScript( ... Google script, CSS, etc. ... );
TextBox txt = new TextBox();
txt.ID = "text1";
this.Controls.Add(txt);
CustomValidator vld = new CustomValidator();
vld.ControlToValidate = "text1";
vld.ID = "validator1";
this.Controls.Add(vld);
}
}
不要考慮我們所需的詳細布局。 關於如何將布局和功能結合起來並仍然擁有一個ASP控件(我們可以進入頁面)的任何建議? 最終目標是讓控件的用戶使用:
<captcha:CaptchaControl ID="CaptchaControl1"
runat="server"
Server="http://localhost:51947/"
/>
並查看工作控件。
抱歉,此功能的基本性質非常感謝。
有兩種方法可以做到這一點。 您可以創建自定義控件或用戶控件。 我認為您會發現執行用戶控件更加容易。 它使您可以像平常頁面一樣對控件的各個部分進行布局。 這是一些示例文檔: http : //msdn.microsoft.com/zh-cn/library/26db8ysc(VS.85).aspx
相比之下,自定義控件通常以代碼形式進行所有呈現(如您所顯示的示例所示)。 以這種方式很難進行首次控制。
盡管您可能希望研究用戶控件,但以下頁面提供了使用Web控件執行此操作的示例。 http://msdn.microsoft.com/zh-cn/library/3257x3ea.aspx Render()方法為控件提供實際HTML的輸出。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.