Image 如何避免任何图像按钮点击后页面加载重新运行? 使用系统; 使用System.Collections.Generic; 使用System.Linq; 使用System.Web; 使用System.Web.UI; 使用System.Web.UI.WebControl; 公共部分类Default2:System.Web.UI.Page { 公开枚举诉讼 { 俱乐部, 钻石, 心, 铁锹 } 公共静态int i=0; 公务舱卡 { 私人诉讼; 私有整数秩; 私有字符串图片库; 公益诉讼 { 获取{返回诉讼;} 设置{suit=value;} } 公共整数级 { 获取{return rank;} 设置{rank=value;} } 公共字符串图片库 { 获取{return pictureUrl;} 设置{pictureUrl=value;} } 公共卡(西服、国际等级、字符串) { 这套衣服; 这个.等级=等级; this.pictureUrl=pictureUrl; } } 受保护甲板(列表甲板) { 对于(int suit=0;suit
这是一个我正在构建的赢形式游戏,其中生成一个随机的5 X 5表格,表格中除了一个空白单元格外,其他都是卡片。你需要在空白单元格周围按图像按钮,切换它们的位置并构建一排扑克牌,但是evrey time我会按一个图像按钮,表格会继续生成。默认情况下,按下按钮将事件发送到服务器(页面将重新加载)。要在客户端中处理它,需要使用OnClientClick属性(http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.onclientclick.aspx)Image 如何避免任何图像按钮点击后页面加载重新运行? 使用系统; 使用System.Collections.Generic; 使用System.Linq; 使用System.Web; 使用System.Web.UI; 使用System.Web.UI.WebControl; 公共部分类Default2:System.Web.UI.Page { 公开枚举诉讼 { 俱乐部, 钻石, 心, 铁锹 } 公共静态int i=0; 公务舱卡 { 私人诉讼; 私有整数秩; 私有字符串图片库; 公益诉讼 { 获取{返回诉讼;} 设置{suit=value;} } 公共整数级 { 获取{return rank;} 设置{rank=value;} } 公共字符串图片库 { 获取{return pictureUrl;} 设置{pictureUrl=value;} } 公共卡(西服、国际等级、字符串) { 这套衣服; 这个.等级=等级; this.pictureUrl=pictureUrl; } } 受保护甲板(列表甲板) { 对于(int suit=0;suit,image,button,Image,Button,这是一个我正在构建的赢形式游戏,其中生成一个随机的5 X 5表格,表格中除了一个空白单元格外,其他都是卡片。你需要在空白单元格周围按图像按钮,切换它们的位置并构建一排扑克牌,但是evrey time我会按一个图像按钮,表格会继续生成。默认情况下,按下按钮将事件发送到服务器(页面将重新加载)。要在客户端中处理它,需要使用OnClientClick属性(http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.o
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default2 : System.Web.UI.Page
{
public enum Suit
{
Club,
Diamond,
Heart,
Spade
}
public static int i = 0;
public class Card
{
private Suit suit;
private int rank;
private string pictureUrl;
public Suit Suit
{
get { return suit;}
set { suit = value; }
}
public int Rank
{
get { return rank; }
set { rank = value; }
}
public string PictureUrl
{
get { return pictureUrl; }
set { pictureUrl = value; }
}
public Card(Suit suit, int rank, string pictureUrl)
{
this.suit = suit;
this.rank = rank;
this.pictureUrl = pictureUrl;
}
}
protected void InitDeck(List<Card> deck)
{
for (int suit = 0; suit < 4; suit++)
for (int rank = 0; rank < 13; rank++)
{
string strPath = "Images\\" + (suit * 13 + rank).ToString() + ".png";
deck.Add(new Card((Suit)suit, rank + 2, strPath));
}
}
protected void InitGameBoard(Card[,] gameBoard, List<Card> deck)
{
Random rnd = new Random();
int rndPosition;
for(int i = 0; i < 5; i++)
for (int j = 0; j < 5; j++)
{
if (i == 4 && j == 4)
{
gameBoard[i, j] = new Card(0, 100, "Images\\b1fv.png");
}
else
{
rndPosition = rnd.Next(0, deck.Count);
gameBoard[i, j] = deck[rndPosition];
deck.RemoveAt(rndPosition);
}
}
}
protected void DrawTable(Card[,] gameBoard)
{
Table gameTable = new Table();
gameTable.GridLines = GridLines.Both;
gameTable.BorderWidth = 4;
gameTable.ID = "gameTable";
ImageButton imgBtn = null;
for (int i = 0; i < 5; i++)
{
TableRow tblRow = new TableRow();
for (int j = 0; j < 5; j++)
{
TableCell tblCell = new TableCell();
tblCell.HorizontalAlign = HorizontalAlign.Center;
imgBtn = new ImageButton();
imgBtn.ID = i.ToString() + j.ToString();
imgBtn.Width = 80;
imgBtn.Height = 105;
imgBtn.ImageUrl = gameBoard[i, j].PictureUrl;
imgBtn.Click += new ImageClickEventHandler(Checking);
tblCell.Controls.Add(imgBtn);
tblRow.Cells.Add(tblCell);
}
gameTable.Rows.Add(tblRow);
}
Panel1.Controls.Add(gameTable);
}
protected void Checking(System.Object sender, System.EventArgs e)
{
ImageButton imgBtn = (ImageButton)sender;
int imgBtnIdNo = int.Parse(imgBtn.ID);
Label1.Text = i.ToString();
}
protected void Page_Load(object sender, EventArgs e)
{
List<Card> deck = new List<Card>();
Card[,] gameBoard = new Card[5, 5];
InitDeck(deck);
InitGameBoard(gameBoard, deck);
DrawTable(gameBoard);
}
}