我有一个关于将会话变量传递到更新面板中的文本框(显示在模式弹出窗口中)的问题。 这是我到目前为止的代码:ASP.NET中的会话变量返回ModalBox中的以前的值?
ASPX CODE:
<asp:TemplateField HeaderText="Link">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" Text="Link" runat="server" OnClick="LinkButton1_Click" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:gridview>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" OnLoad="panel_Load">
<ContentTemplate>
<asp:Button ID="OKButton" runat="server" Text="Close" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
<asp:ModalPopupExtender ID="mpe" runat="server" TargetControlID="ClientButton" PopupControlID="UpdatePanel1" OkControlID="OKButton">
</asp:ModalPopupExtender>
<asp:Button ID="ClientButton" runat="server" Text="Launch Modal Popup (Client)" style="display:none;" />
后面的代码(C#):
protected void LinkButton1_Click(object sender, EventArgs e)
{
GridViewRow clickedRow = ((LinkButton)sender).NamingContainer as GridViewRow;
Label lbl_nme = (Label)clickedRow.FindControl("lbl_name");
String string_nme = lbl_nme.Text.ToString();
Session["Name"] = string_nme;
mpe.Show();
}
protected void panel_Load(object sender, EventArgs e)
{
Label1.Text = (string)(Session["Name"]);
}
所以基本上我有一个GridView与名称,地址等......当用户点击一行中的链接时,该行的名称字段的值将被保存为会话变量。然后显示一个模态弹出窗口。 Modal PopUp应该显示保存为Session变量的Name。
作品的代码种类。我正在经历的是,当我点击一行时,Modal PopUp中的Label1.Text为空。因此,如果我关闭了PopUp,然后点击另一行中的另一个链接,PopUp会显示之前点击过的行的名称。
换句话说,如果第1行的名称为“Kevin”,第2行的名称为“Nathaniel”,并且我单击链接打开第1行的Modal PopUp,我希望PopUp显示“Kevin” 。但事实并非如此。在重建应用程序后第一次单击链接时,不显示任何内容。但是,如果点击row1后点击第2行,那么Modal PopUp会显示我之前点击的行的值,即“Kevin”,当我期望它是“Nathaniel”时。
我希望我没有混淆任何人。我是一个新手,我只是进入这个东西,所以我会很感激,如果有人可以帮助我,最好用代码等例子。
谢谢。非常感激。
谢谢。这是完美的。非常感激! :) –
@KevinP不客气。 ASP.NET的生命周期相当复杂...... – 2012-05-09 20:14:32