說明:點選GridView內的LinkButtion下載檔案時,需在子視窗TextBox輸入原因才可回母視窗動作。
做法:使用Session來判斷子視窗TextBox是否有值。
//Son.aspx
<form id="form1" runat="server">
<div>
<asp:HiddenField ID="hidFileID" runat="server" />
<asp:TextBox ID="txtReason" runat="server"></asp:TextBox>
<asp:Button ID="btnSave" runat="server" Text="儲存" onclick="btnSave_Click" />
</div>
</form>
//Son.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
Session["Reason"] = null;
}
protected void btnSave_Click(object sender, EventArgs e)
{
bool blReturn = false;
if (!string.IsNullorEmpty(txtReason.Text))
{
if (!string.IsNullorEmpty(hidFileID.Value))
{
blReturn = 呼叫儲存資料method;
if (!blReturn)
{
//showMsg("error");
}
else
{
Session["Reason"] = txtReason.Text;
//儲存原因後關閉子視窗
Response.Write("<script>window.close();</script>");
}
}
}
}
Parent.aspx
<asp:BoundField DataField="File_ID" HeaderText="檔案代碼" />
<asp:BoundField DataField="File_Path" HeaderText="檔案路徑" />
<asp:TemplateField HeaderText="下載">
<ItemTemplate>
<asp:LinkButton ID="lbtnDownload" runat="server" OnCommand="FileDownload" CommandArgument='<%# Eval("File_Path") %>'>
</ItemTemplate>
</asp:TemplateField>
Parent.aspx.cs
protected void FileDownload(Object sender, CommandEventArgs e)
{
string strFile_Path = e.CommandArgument.ToString();
if (Session["Reason"] == null || Session["Reason"].ToString() == "")
{
//showMsg("無輸入原因");
return;
}
else
{
//下載檔案
}
}
參考資料:
http://www.programmer-club.com.tw/ShowSameTitleN/aspdotnet/6117.html
沒有留言:
張貼留言