我使用这个java脚本将页面id组件id和模板id作为查询字符串传递给aspx页面:
var masterTabControl = $controls.getControl($("#MasterTabControl"),
"Tridion.Controls.TabControl");
p.compPresTab = masterTabControl.getPage("ComponentPresentationsTab");
p.selectedComponentPresentation = p.compPresTab.getSelectedComponentPresentation();
p.selectedComp = p.selectedComponentPresentation.getComponentId();
window.open("http://" + location.hostname + ":path/test.aspx?pgId=" + pageId +
"&comId=" + p.selectedComponentPresentation.getComponentId() +
"&comTmpId=" +
p.selectedComponentPresentation.getComponentTemplateId(),
"myWindow", "status = 1,
toolbar=no,width=300,height=200,resizable=no,scrollbars=yes");
现在在 test.aspx 页面上,我正在读取 id 并使用来自用户的一些附加信息将其保存到文本文件中。
在按钮上单击弹出 test.aspx 页面,我将其保存在文本文件中:
sLogDetails = PageId + "| " + ComponentId + "|" + ComponentTemplateId +
"|" + text ;
//Move the contents to the temp file other than the existing one.
using (var sr = new StreamReader(permanentFile))
{
using (var sw = new StreamWriter(@"" + tempFile , true))
{
string line;
while ((line = sr.ReadLine()) != null)
{
string[] parts = line.Split('|');
PageId = parts[0].Trim();
ComponentId = parts[1].Trim();
ComponentTemplateId = parts[2].Trim();
//Check there exist same record already
if (SPageId != PageId.Trim() || SComponentId != ComponentId.Trim()
|| SComponentTemplateId != ComponentTemplateId.Trim())
sw.WriteLine(line);
}
//Delete the Permanent file & create permanent file from temporary file
File.Delete(permanentFile);
File.Move(tempFile, permanentFile);
// Insert changes to the Permanent file
using (StreamWriter w = File.AppendText(permanentFile))
{
// Close the writer and underlying file.
w.WriteLine(sLogDetails);
w.Flush();
w.Close();
}
如果 id 已经存在于文本文件中,那么我将其填充到 popup test.aspx 页面上的文本字段中,例如:
using (StreamReader r = File.OpenText(strPath + "Log.txt"))
{
string line;
while ((line = r.ReadLine()) != null)
{
// Console.WriteLine(line);
string[] parts = line.Split('|');
PageId=parts[0].Trim();
ComponentId = parts[1].Trim();
ComponentTemplateId = parts[2].Trim();
//If there exist a record populate the data fields
if (SPageId == PageId.Trim() && SComponentId == ComponentId.Trim()
&& SComponentTemplateId == ComponentTemplateId.Trim())
{
txtRuleName.Text = (string)parts[3];
}
}
r.Close();
}
现在我被困在这里。当它填充在文本字段中时,用户可以在弹出的 test.aspx 页面中编辑文本区域,单击“确定”将保存在文本文件中。如果用户在没有“保存并关闭”的情况下关闭页面窗口,那么他在文本字段中所做的更改不应保存在文本文件中。它应该恢复到旧的。
知道我该怎么做吗?