c#在后台如何获取自动生成的编号
1、打开Visual Studio 2015,如下图所示:

3、新建“ASP.NET Web应用程序”,如下图所示:

5、右键解决方案,选择“添加”->“新建项...”,如下图所示:

7、在WebForm1.aspx文件中添加如下代码:<%@ Page Language="稆糨孝汶;C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication11.WebForm1" %><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> <script src="Scripts/jquery-1.10.2.js"></script> <script> function fRandomBy(under, over) { switch (arguments.length) { case 1: return parseInt(Math.random() * under + 1); case 2: return parseInt(Math.random() * (over - under + 1) + under); default: return 0; } } $(function () { var random = fRandomBy(1, 100); alert(random); $("<%= hd.ClientID%>").val(random); }); </script></head><body> <form id="form1" runat="server"> <div> <asp:Button ID="btnRandom" runat="server" Text="获取自动生成的编号" OnClick="btnRandom_Click" /> </div> <asp:HiddenField ID="hd" runat="server" /> </form></body></html>

9、右键WebForm1.aspx,选择“在浏览器中打开”,点击按钮可以看到生成的值,如下图所示:
