Click here to Skip to main content
15,890,670 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to create input box when i click the button in asp.net. And I am using that inputbox value to CS file. How to do it? please help me
Posted

Hi devausha,

Try the following code:

protected void Button1_Click1(object sender, EventArgs e)
    {
        string script = "<script language='javascript'>alert('message!')"+"</script>";
        Page.RegisterStartupScript("JavaScript",script);

        HtmlInputText input = new HtmlInputText();
        input.ID = "i1";
        input.Value = "123";
        form1.Controls.Add(input );
       
    }
 
Share this answer
 
You're right in saying that it is more complicated with a web app. In a windows app, whenever you run the C# code, whatever happens, happens at that moment. It's pretty straightforward. However, in a web app, all of the C# runs before the page is even rendered in the browser. Therefore, C# in web forms can't really pop up a window.

In order to get a popup, you'll need to do that with JavaScript. The textbox inside the popup should be an <asp:textbox> control. You can use the Ajax Control Toolkit[^] if youre most comfortable with .NET controls. If youre comforatble with jQuery, you should check out jQuery UI[^].



--Amit
 
Share this answer
 
v2
There can be different ways to do it:
1. using Javascript - you need to track the value inserted in textbox via hidden field
2. using AJAX

Here, have a look at these:
MSDN: How to: Add Controls to an ASP.NET Web Page Programmatically[^]
How To Create TextBox Dynamically using Javascript and Read Control Value In Code Behind[^]
Dynamically Created Controls in ASP.NET[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900