.NET 专业人士
我有一个问题想和你分享,如果可能的话,得到一个建议:
我正在使用 datalist 动态加载用户控件。我正在为从数据库中获取的每一行加载这个用户控件,它可能是这个控件的 30 个不同的实例。
当用户单击按钮时,我希望能够获取此特定用户控件属性的值,据我了解,我注意到用户控件 ID 这样做,这就是为什么我想将我的“自定义 ID”分配给每个加载的控件所以我以后可以找到它。也许我错过了一些东西,也许这不是最好的方法,我愿意接受建议。反正.....
后面的 UserControl 代码:
public partial class SearchBullet : System.Web.UI.UserControl
{
public static int i = 0;
private string casterLOGO;
public string CasterLOGO
{
get { return casterLOGO; }
set { casterLOGO = value; }
}
private string casterNameSB;
public string CasterNameSB
{
get { return casterNameSB; }
set { casterNameSB = value; }
}
private string player1NameSB;
public string Player1NameSB
{
get { return player1NameSB; }
set { player1NameSB = value; }
}
private string player2NameSB;
public string Player2NameSB
{
get { return player2NameSB; }
set { player2NameSB = value; }
}
private string mapSB;
public string MapSB
{
get { return mapSB; }
set { mapSB = value; }
}
private string gameFrameSB;
public string GameFrameSB
{
get { return gameFrameSB; }
set { gameFrameSB = value; }
}
private string serieSB;
public string SerieSB
{
get { return serieSB; }
set { serieSB = value; }
}
private string race1SB;
public string Race1SB
{
get { return race1SB; }
set { race1SB = value; }
}
private string race2SB;
public string Race2SB
{
get { return race2SB; }
set { race2SB = value; }
}
private string castURLSB;
public string CastURLSB
{
get { return castURLSB; }
set { castURLSB = value; }
}
private string likeAmountSB;
public string LikeAmountSB
{
get { return likeAmountSB; }
set { likeAmountSB = value; }
}
private string qRYstring;
public string QRYstring
{
get { return qRYstring; }
set { qRYstring = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack == false)
{
i++;
this.PreRender += new EventHandler(Cast_PreRender);
this.ID = "Result" + i.ToString();
}
PlayButton.ID = i.ToString();
}
void Cast_PreRender(object sender, EventArgs e)
{
PlayerName1.Text = Player1NameSB;
PlayerName2.Text = Player2NameSB;
CasterName.Text = CasterNameSB;
ImageRace1.ImageUrl = Race1SB;
ImageRace2.ImageUrl = Race2SB;
Map.Text = MapSB;
GameFrame.Text = GameFrameSB;
LikeAmount.Text = LikeAmountSB;
CasterLOGOIMG.ImageUrl = CasterLOGO;
PlayButton.AlternateText = "yay";
}
protected void PlayButton_Click1(object sender, ImageClickEventArgs e)
{
Image img = (Image)sender;
string tt = img.AlternateText;
int j = 0;
Response.Redirect("default2.aspx");
// lb.Text = img.ClientID;
}
}
aspx 页面:
<asp:DataList ID="WatchLaterDL" runat="server" DataSourceID="SDSWatchLater" RepeatColumns="1">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<Search:Bullet runat="server" EnableViewState="false" ID="SearchResults" Player1NameSB='<%#Bind("Player_Name") %>'
Player2NameSB='<%#Bind("Expr1") %>' CasterNameSB='<%#Bind("Caster_Name") %>'
Race1SB='<%#Bind("Race_1") %>' Race2SB='<%#Bind("Race_2") %>' MapSB='<%# Bind("Map")%>'
GameFrameSB='<%#Bind("Game_Frame") %>' LikeAmountSB='<%#Bind("Like_Amount") %>'
CastURLSB='<%#Bind("Cast_URL") %>' CasterLOGO='<%#Bind ("Caster_LOGO") %>' />
</ItemTemplate>
<SeparatorTemplate>
<br />
</SeparatorTemplate>
</asp:DataList></div>
问题是,在这样做之后,当我单击按钮时没有任何反应,我的意思是,在调试时,我永远不会进入 OnButton_Click 事件。如果我删除 --> this.ID = "Result" + i.toString(); 还有--> PlayButton.ID = i.ToString(); 没关系。
如果还有其他问题,您可能需要评估我的问题,我很乐意证明并需要额外的代码。非常感谢您的帮助。