My name is elli and im doing some project for school, i will very much appreciate you advice.
I have a number of instances of a user control in my aspx page. the data in the user control i get from a datalist.
inside the control i have a button. what im trying to do is like that:
when a user clicks the button, i want to find out what row from the datalist is presented in this specific control, and store it in, lets say, session.
my problem right now is when i click the button, nothing happens, i tried just to put a simple Response.Redirect in the onButton_click in the code behind...
im working on it already 2 days and im kinda lost.
this is my user control ascx partial code: the image button is in the beggining
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
public partial class SearchBullet : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
String tmpcmd;
tmpcmd = (String)(Session["mainSearchQRY"]);
SqlDataSource1.SelectCommand = "";
SqlDataSource1.SelectCommand = tmpcmd;
}
protected void PlayButton_Click(object sender, EventArgs e)
{
Response.Redirect("Default2.aspx");
}
}
ellipertzov
Member
6 Points
20 Posts
how to get the data bound to an instance of a user control
Apr 09, 2012 05:31 PM|LINK
Hello to all the pros....
My name is elli and im doing some project for school, i will very much appreciate you advice.
I have a number of instances of a user control in my aspx page. the data in the user control i get from a datalist.
inside the control i have a button. what im trying to do is like that:
when a user clicks the button, i want to find out what row from the datalist is presented in this specific control, and store it in, lets say, session.
my problem right now is when i click the button, nothing happens, i tried just to put a simple Response.Redirect in the onButton_click in the code behind...
im working on it already 2 days and im kinda lost.
this is my user control ascx partial code: the image button is in the beggining
<div id="video play button icon" style="height: 27px; width: 121px; float: left"><asp:ImageButton ID="PlayButton" runat="server" ImageUrl="~/Search_Results_Images/search_Play_Button_Icon.png" onclick="PlayButton_Click" /> </div> <div style="height: 27px; width: 22px; float: left"> </div> </div> <div style="height: 15px; width: 434px; background-color: transparent; float: left"> </div> </div> </div> </ItemTemplate> <SeparatorTemplate> <div style="width:84px"></div> </SeparatorTemplate> </asp:DataList>using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Text; using System.Data.SqlClient; using System.Data; using System.Configuration; public partial class SearchBullet : System.Web.UI.UserControl { protected void Page_Load(object sender, EventArgs e) { String tmpcmd; tmpcmd = (String)(Session["mainSearchQRY"]); SqlDataSource1.SelectCommand = ""; SqlDataSource1.SelectCommand = tmpcmd; } protected void PlayButton_Click(object sender, EventArgs e) { Response.Redirect("Default2.aspx"); } }nirman.doshi
Participant
1521 Points
783 Posts
Re: how to get the data bound to an instance of a user control
Apr 09, 2012 05:41 PM|LINK
Your mark-up says - PlayButton_Click
And your cs file does not have it, rather it has - btnClick_Click.
is it the case really, or is it just a typo?
usercontol
Software Developer
Vadodara, India
ellipertzov
Member
6 Points
20 Posts
Re: how to get the data bound to an instance of a user control
Apr 09, 2012 06:00 PM|LINK
it is just a type mistake. this is not the problem...
when i click the button, nothing happens, the page refresh itself and thats all.....
thanks for your response....
usercontol
nirman.doshi
Participant
1521 Points
783 Posts
Re: how to get the data bound to an instance of a user control
Apr 09, 2012 06:23 PM|LINK
It seems you are rebinding your DataList in Page Load event.
Its ok to keep it there, but try putting that code in -
if (Page.IsPostBack == false)
{
--- move your rebind code here
}
Software Developer
Vadodara, India
ellipertzov
Member
6 Points
20 Posts
Re: how to get the data bound to an instance of a user control
Apr 09, 2012 07:08 PM|LINK
you right, but this is not the problem.....right?
Johnson-zhu
Member
340 Points
45 Posts
Re: how to get the data bound to an instance of a user control
Apr 12, 2012 03:40 AM|LINK
Hi elli,
please check your code-behind of user control, it should like this:
protected void PlayButton_Click(object sender, ImageClickEventArgs e) { Response.Redirect("ShowProduct.aspx"); }your parameter of the method is not currect.
ellipertzov
Member
6 Points
20 Posts
Re: how to get the data bound to an instance of a user control
Apr 13, 2012 01:36 PM|LINK
thank you