我在页面上有两个图像按钮。单击其中一个时,需要在回发页面之前设置会话变量 yesID 和 NoId。我尝试将代码放入每个按钮的单击事件中,但页面在单击事件中运行该代码之前再次加载。单击任一图像时,如何设置 2 个会话变量?
<div id="MainPics">
<div id="RightPic">
<p>
<asp:Label ID="FirstPicMemberNameLabel" runat="server" Text="" Font-Bold="True" ForeColor="White"></asp:Label>
</p>
<asp:ImageButton ID="FirstPicLink" Width="90%" runat="server"
onclick="FirstPicLink_Click" />
</div>
<div id="LeftPic">
<p>
<asp:Label ID="SecondPicMemberNameLabel" runat="server" Text="" ForeColor="White" Font-Bold="True"></asp:Label>
</p>
<asp:ImageButton ID="SecondPicLink" Width="90%" runat="server"
onclick="SecondPicLink_Click" />
</div>
<div id="skip">
<asp:LinkButton ID="LBNoChoice" PostBackUrl="~/default.aspx" ForeColor="White" runat="server">Skip - I Can't Choose</asp:LinkButton>
</div>
</div>
页面背后的代码
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Session["yesID"] = 0;
Session["noId"] = 0;
}
else
{
//Send Session Variables to Database for Storage.
}
}
protected void FirstPicLink_Click(object sender, ImageClickEventArgs e)
{
Session["yesID"] = 1;
Session["noId"] = 2;
}
protected void SecondPicLink_Click(object sender, ImageClickEventArgs e)
{
Session["yesID"] =2;
Session["noId"] = 1;
}