Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7536993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:43:36+00:00 2026-05-30T06:43:36+00:00

This is frustrating, I want to simply create new input field inside div on

  • 0

This is frustrating, I want to simply create new input field inside div on my aspx page when button is clicked. I use javascript function witch appends new child element(input field) to existing div. It all looks like this:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="Pages_test" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">

        function clone() {
            var html = document.createElement("input");
            html.setAttribute("id", 1);
            html.setAttribute("name", "dejan");
            html.setAttribute("value", "some text");
            html.setAttribute("type", "text");
            document.getElementById("panj").appendChild(html);
        }

    </script>
</head>
    <body>
        <form id="form1" runat="server">
            <div id="panj">
                Djubrov
            </div>
            <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="clone()" />
        </form>
    </body>
</html>

Funny thing is that text element with set text value flashes for second when i click the button but it disappears afterwords. Do I missing something?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T06:43:38+00:00Added an answer on May 30, 2026 at 6:43 am

    If you need the value from this generated text field in code behind, you would be much better off not to create it dynamically via Javascript. You could just create a normal textbox and set it to be initially invisible like so:

    <asp:TextBox ID="yourTextboxID" Visible="False" runat="server" />
    

    When the button is pressed, handle the event in the code behind and make the textbox visible:

    yourTextboxID.Visible = True;
    

    Viewstate will keep the values across postbacks.

    If each button press should create an additional textbox, you could also do this in the codebehind, i.e. use a placeholder in the ascx and then attach a new textbox to it with each button press:

    yourPlaceholderID.Controls.Add(new TextBox() { ID = "textbox1" });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is frustrating and I simply can't find the right answer on how to
this is frustrating... I keep getting an error with my ftp_put: This the error:
I've been having this rather frustrating problem, and having failed so many times, I'm
Well this is incredibly frustrating. After being nagged by Rails that I need to
I need help finishing this statement. It is frustrating that two of the PHP
I'm just diving into WPF and find this a little odd and frustrating to
First of all thanks in advance, this has been very frustrating and I'm hoping
This is driving me wild with frustration. I am just trying to create a
I'm using this code and I'm beyond frustration: try { $dbh = new PDO('mysql:dbname='
I occasionally get this problem, and generally work around it, but it's rather frustrating.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.