the problem is, after doing this, when i click the button nothing happens, i mean, when debugging, i never get inside the OnButton_Click event. if i delete the --> this.ID = "Result" + i.toString(); and the--> PlayButton.ID = i.ToString(); it's ok. here is the onClick code
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; }
}
in addition, this is the aspx page where i load the user control, may this has to do with the problem:
ellipertzov
Member
6 Points
20 Posts
Why OnClick event of a button inside usercontrol not happening
Apr 13, 2012 01:34 PM|LINK
Greetings to all the ASP.NET pros out there
I have a problem that i would like to share with you and if possible get an advice:
I am loading a usercontrol dynamically using datalist. inside this usercontrol i have a imgbuttton.
in order to find the specific usercontrol who's button was clicked, iam trying to assign a customized ID to the userControl, and the button like this:
Setting the id for the UserControl:
protected void Page_Load(object sender, EventArgs e) { i++; this.PreRender += new EventHandler(Cast_PreRender); this.ID = "Result" + i.ToString(); }Setting the id for the button
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.ID = i.ToString(); }the problem is, after doing this, when i click the button nothing happens, i mean, when debugging, i never get inside the OnButton_Click event. if i delete the --> this.ID = "Result" + i.toString(); and the--> PlayButton.ID = i.ToString(); it's ok. here is the onClick code
protected void PlayButton_Click1(object sender, ImageClickEventArgs e) { Image img = (Image)sender; string tt = img.ID.ToString(); Response.Redirect("default2.aspx"); // lb.Text = img.ClientID; }if there anything elese you might need to evaluate my problem, ill gladly prove and additional code needed.
thank you very much for your help,
elli pertzov
mm10
Contributor
6395 Points
1182 Posts
Re: Why OnClick event of a button inside usercontrol not happening
Apr 13, 2012 02:37 PM|LINK
If you move the assignment of the ID for the PlayButton from the PreRender to the Load event it will probably work.
ellipertzov
Member
6 Points
20 Posts
Re: Why OnClick event of a button inside usercontrol not happening
Apr 13, 2012 03:06 PM|LINK
hi mm10, thanks for your response,
this is not working
i have it written like this
protected void Page_Load(object sender, EventArgs e) { if (IsPostBack == false) { i++; this.PreRender += new EventHandler(Cast_PreRender); PlayButton.ID = i.ToString(); this.ID = "Result" + i.ToString(); } }still nothing happens, it is not getting to the onclick event. any other ideas?
mm10
Contributor
6395 Points
1182 Posts
Re: Why OnClick event of a button inside usercontrol not happening
Apr 13, 2012 05:19 PM|LINK
Set it on every request to make it work on the first postback:
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();
}
nirman.doshi
Participant
1520 Points
775 Posts
Re: Why OnClick event of a button inside usercontrol not happening
Apr 13, 2012 06:39 PM|LINK
Software Developer
Vadodara, India
ellipertzov
Member
6 Points
20 Posts
Re: Why OnClick event of a button inside usercontrol not happening
Apr 13, 2012 07:40 PM|LINK
hi again,
the postback condition is not the problem, i dont know what is, but for sure is not the postback, i added this condition just now.
ofcourse i tried what you suggested, nothing new there.....:)
ellipertzov
Member
6 Points
20 Posts
Re: Why OnClick event of a button inside usercontrol not happening
Apr 13, 2012 07:44 PM|LINK
hi nirman, thank you for your response...
Here the declaration of the "i":
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; } }in addition, this is the aspx page where i load the user control, may this has to do with the problem:
<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>thanks again for your help
ellipertzov
Member
6 Points
20 Posts
Re: Why OnClick event of a button inside usercontrol not happening
Apr 14, 2012 09:55 PM|LINK
my solution was like this:
instead of using an image buttom, i used Hyperlink.
on_Load event of the usercontrol, i assigned to the src Attribute of the hyperlink all the properties of my user control and passed those using
querystring to another page.