如何在asp.net中创建输入框 [英] how to create inputbox in asp.net
本文介绍了如何在asp.net中创建输入框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我单击asp.net中的按钮时,我想创建输入框.我正在使用该inputbox值到CS文件.怎么做?请帮助我
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
推荐答案
您好devausha,
尝试以下代码:
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 );
}
您说对了,因为它对于Web应用程序来说更加复杂.在Windows应用程序中,无论何时运行C#代码,任何事情都会在那一刻发生.这很简单.但是,在Web应用程序中,所有C#都在页面甚至在浏览器中呈现之前运行.因此,Web窗体中的C#不能真正弹出一个窗口.
为了获得一个弹出窗口,您需要使用JavaScript来实现.弹出窗口中的文本框应为<asp:textbox>
控件.您可以使用 Ajax控制工具包 [ jQuery UI [
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
可以有不同的方法:
1.使用Javascript-您需要通过隐藏字段跟踪在文本框中插入的值
2.使用AJAX
在这里,看看这些:
MSDN:如何:以编程方式将控件添加到ASP.NET网页 [ ^ ]
如何使用Javascript动态创建文本框并在后面的代码中读取控件值 [ ^ ]
在ASP.NET中动态创建的控件 [
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[^]
这篇关于如何在asp.net中创建输入框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文