Basically, what I am trying to do is send information via PreviousPage somehow, but can't figure out how. Let me explai:
On One page (FirstPage.aspx) I have a DataList(Id = "DataList") which contains Labels(Id = "Label") ImageButtons (Id = "ImageButton"). Now when I press an ImageButton with PostbackUrl to second page, I need a way to get the Text from the label, but from the label from the selected item.
I've tried:
DataList idDataList = (DataList)(Page.PreviousPage.FindControl("DataList"));
Label idLabel = (Label)idDataList.SelectedItem.FindControl("Label");
string id = idLabel.Text;
but I get null on idDataList.
Also read that you can put an OnClick event on the ImageButton and the server executes both OnClick and PostBackUrl, but in vain. I mention that OnCLick event is on server. My next try is to put OnClick on client with javascript and will post back. Thanks in advance!!!
Loading
George OnofreiPosted Jan 9, 2011, 3:22 PM
give up labels and use ImageButton with onbuttonclick="
Madhu KPosted Jan 8, 2011, 1:35 PM
You can do it using ItemCommand event set commnadname property of image button
In itemcommnd event
Label idLabel = (Label)idDataList.SelectedItem.FindControl("Label");
If(e.CommandName=="ImagebuttonCommandName")
{
Response.Redirect("NewPage.aspx?Label="+idLabel);
}
In your new page pageload event
string labelvalue=Request.QueryString["Label"].ToString();