简体   繁体   English

ASP.NET中的格式设置控件

[英]Formatting Controls in ASP.NET

I feel as though this this is a simple question, but can't find an answer anywhere. 我觉得这似乎是一个简单的问题,但是在任何地方都找不到答案。 We've got an interface we're trying to move to an ASP.NET control. 我们有一个接口,试图将其移至ASP.NET控件。 It currently looks like: 当前看起来像:

<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>

However all the examples I see of ASP.NET controls that allow for basical functionality - ie 但是,我看到的所有允许基本功能的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);
}
}

Don't allow for the detailed layout that we need. 不要考虑我们所需的详细布局。 Any suggestions on how I can combine layout and functionality and still have a single ASP control we can drop in to pages? 关于如何将布局和功能结合起来并仍然拥有一个ASP控件(我们可以进入页面)的任何建议? The ultimate goal is for users of the control to just drop in: 最终目标是让控件的用户使用:

<captcha:CaptchaControl ID="CaptchaControl1" 
runat="server"
Server="http://localhost:51947/"
/>

and see the working control. 并查看工作控件。

Sorry for the basic nature of this one, any help is greatly appreciated. 抱歉,此功能的基本性质非常感谢。

There are a couple of ways to do it. 有两种方法可以做到这一点。 You can make a custom control, or a user control. 您可以创建自定义控件或用户控件。 I think you will find it easier to do a user control. 我认为您会发现执行用户控件更加容易。 It lets you lay out parts of your control as you would a regular page. 它使您可以像平常页面一样对控件的各个部分进行布局。 Here is some example documentation: http://msdn.microsoft.com/en-us/library/26db8ysc(VS.85).aspx 这是一些示例文档: http : //msdn.microsoft.com/zh-cn/library/26db8ysc(VS.85).aspx

By contrast a custom control typically does all of the rendering in code (as your example you show). 相比之下,自定义控件通常以代码形式进行所有呈现(如您所显示的示例所示)。 It is harder to make your first control in this way. 以这种方式很难进行首次控制。

Although you may want to look into user controls, the following page has an example of doing this using a web control. 尽管您可能希望研究用户控件,但以下页面提供了使用Web控件执行此操作的示例。 http://msdn.microsoft.com/en-us/library/3257x3ea.aspx The Render() method does the output of the actual HTML for the control. http://msdn.microsoft.com/zh-cn/library/3257x3ea.aspx Render()方法为控件提供实际HTML的输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM