As @TheVillageIdiot said, url rewriting is a better approach. But you can use cross-page posting ability as well. Check it out:
Markup
<asp:HiddenField ID="HiddenField1" runat="server" ClientIDMode="Static" />
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" PostBackUrl="~/Second.aspx" Text='<%# Bind("Text") %>' OnClientClick='<%# "LinkButton1_Click(\"" + Eval("Value") + "\")" %>' />
</ItemTemplate>
</asp:Repeater>
<script type="text/javascript">
function LinkButton1_Click(v) {
document.getElementById('HiddenField1').value = v;
}
</script>
As you can see in the preceding code snippet, you have to add a hidden field to store the selected item by a simple javascript. Also I defined a property, called SelectedValue
to get the value of the hidden field on the otherside.
Code Behind
protected void Page_Load(object sender, EventArgs e)
{
Repeater1.DataSource = new[] {
new { Text = "Item 1", Value = "Item 1" },
new { Text = "Item 2", Value = "Item 2" },
new { Text = "Item 3", Value = "Item 3" }
};
Repeater1.DataBind();
}
public string SelectedValue
{
get { return HiddenField1.Value; }
}
Second Page
Add following directive to the destination page.
<%@ PreviousPageType VirtualPath="~/Default.aspx" %>
Finally, you have access to the previous page via PreviousPage
property of Page
class.
string value = ((_Default)this.PreviousPage).SelectedValue;