如何在asp.net 2.0的文本框中生成自动生成的 [英] how to generate autogenerated in textbox in asp.net 2.0

查看:64
本文介绍了如何在asp.net 2.0的文本框中生成自动生成的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本框,我希望该文本框会自动在其中生成自动生成的int值.如何完成此操作,请提前帮助我thnx

我有一个文本框.我希望此文本框应在其中(页面加载时)包含一个自动生成的(随机)"int"值.

i have a textbox i want that automatically this textbox will generate autogenerated int value in it..how it can done please help me thnx in advance

I have a textbox. I want that this textbox should contain a autogenerated (random )''int'' value in it (on page load). How can it be done?

推荐答案

以下代码可以帮助您入门.您可以使用它并进行所需的更改.希望对您有帮助.
在ASPX文件中,将textbox属性设置为AutoPostBacktrue.

Following code can help you in starting. You can use it and make the required changes. Hope it helps you.
In the ASPX file, set the textbox property to AutoPostBack to true.

<![CDATA[<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" 

    CodeBehind="Default.aspx.cs" Inherits="TestingATextBox._Default" Culture="Auto" %>]]> 
 
<asp:content id="HeaderContent" runat="server" contentplaceholderid="HeadContent" xmlns:asp="#unknown"> 
</asp:content> 
<asp:content id="BodyContent" runat="server" contentplaceholderid="MainContent" xmlns:asp="#unknown"> 
    <table> 
        <tr> 
            <td> 
                <asp:textbox runat="server" id="TextBox1" autopostback="true"> 
                </asp:textbox> 
            </td> 
        </tr> 
        <tr> 
            <td> 
                <asp:button runat="server" id="SaveBtn" text="Save" onclick="SaveBtn_Click" /> 
            </td> 
        </tr> 
    </table> 
</asp:content>



在后面的代码中,单击Save按钮,递增该值.



In the codebehind, on Save button click, increment the value.

public partial class _Default : System.Web.UI.Page 
    { 
        static int i = 1; 
        protected void Page_Load(object sender, EventArgs e) 
        { 
            TextBox1.Text = i.ToString(); 
        } 
 
        protected void SaveBtn_Click(object sender, EventArgs e) 
        { 
            i++; 
        } 
    }


这篇关于如何在asp.net 2.0的文本框中生成自动生成的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆