开发者

How do I add this (recaptcha) form dynamically?

开发者 https://www.devze.com 2023-03-04 05:42 出处:网络
I have a .aspx file and I want to dynamically add the form and controls below in my <script> tag. (Page-Language=C#)

I have a .aspx file and I want to dynamically add the form and controls below in my <script> tag. (Page-Language=C#)

<form runat="server">
        <asp:Label Visible=true ID="lblResult" runat="server" />

        <recaptcha:RecaptchaControl
            ID="recaptcha"
            runat="server"
            Theme="red"
            PublicKey="6Ld4PcQSAAAAADvExkhlgujfXixYYeJ0x6zQDZan"
            PrivateKey="6Ld4PcQSAAAAABAg0i2Nk6FMjbstXQqCS2XRDoea"
        />
        <br />
        <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClic开发者_如何转开发k="btnSubmit_Click" />
</form>


Why do you want to add it dynamically? Although, its not exactly the answer to your question but more simpler way is to put the said markup in the placeholder control and sets placeholder's visibility as per your requirements.

And if you must add controls dynamically, you will still need a placeholder (after script tag) as parent and then you can create the need control hierarchy from code-behind. For example,

var form = new HtmlForm();

var label = new Label();
label.ID = "lblResult";
form.Controls.Add(label);

var captcha = new RecaptchaControl();
captcha.ID = "recaptcha";
...

placeholder.Controls.Add(form);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号