我在aspx区域的中继器如下:
this repeater is inside a master page - pages are base on master and content pages
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand">
<ItemTemplate>
<asp:Image ID="imgArrowIconInsideRepeater" runat="server" ImageUrl="~/Images/Login/ArrowIcon.png"
/>
<asp:HiddenField ID="hfFilePath" runat="server" Value='<%# Eval("FilePath")%>' />
<asp:HiddenField ID="hfFileName" runat="server" Value='<%# Eval("FileName")%>' />
<asp:HiddenField ID="hfFileSize" runat="server" Value='<%# Eval("FileSize")%>' />
<asp:HiddenField ID="hfFileCreationDate" runat="server" Value='<%# Eval("FileCreationDate")%>' />
<asp:LinkButton ID="lbFile" runat="server" CommandName="lbFile_Click" CssClass="lbFileInRepeater"
><%# Eval("FileName")%></asp:LinkButton>
<br />
<asp:Label ID="lblFileCreationDate" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "FileCreationDate", "{0:yyyy/MM/dd - tt h:m:s}") %>'
CssClass="lblFileCreationDateInRepeater" ></asp:Label>
|
<asp:Label ID="lblFileSize" runat="server" Text='<%# GetFileSize(Eval("FileSize"))%>'
CssClass="lblFileSizeInRepeater"></asp:Label>
<div class="EmptyDiv">
</div>
</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
我的主页面中也有一个脚本管理器,如下所示:
<telerik:RadScriptManager ID="RadScriptManager1" runat="server" EnablePageMethods="True">
</telerik:RadScriptManager>
后面代码中的c#代码如下所示:
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
//The Below Line Does Not Work - Always Is Null
//NewAddedFiles currentItem = (NewAddedFiles)e.Item.DataItem;
HiddenField hfFilePath = (HiddenField)e.Item.FindControl("hfFilePath");
HiddenField hfFileName = (HiddenField)e.Item.FindControl("hfFileName");
HiddenField hfFileSize = (HiddenField)e.Item.FindControl("hfFileSize");
HiddenField hfFileCreationDate = (HiddenField)e.Item.FindControl("hfFileCreationDate");
switch (e.CommandName)
{
case "lbFile_Click":
{
if (Session["User_ID"] != null)
{
DataSet dsDownload = DataLayer.Download.Size_By_UserID_Today(int.Parse(HttpContext.Current.Session["User_ID"].ToString()), DateTime.Now);
if (dsDownload.Tables["Download"].Rows.Count > 0)
{
DataRow drDownload = dsDownload.Tables["Download"].Rows[0];
int SumOfFileSize4Today = int.Parse(drDownload["FileSizSum"].ToString());
if (SumOfFileSize4Today + int.Parse(hfFileSize.Value) <= 1073741824)//1 GB = 1024*1024*1024 bytes = 1073741824 bytes
//if (SumOfFileSize4Today + int.Parse(hfFileSize.Value) <= 100000)
{
DataLayer.Download.InsertRow(
int.Parse(HttpContext.Current.Session["User_ID"].ToString()),
DateTime.Now,
hfFilePath.Value,
hfFileName.Value,
hfFileSize.Value,
DateTime.Parse(hfFileCreationDate.Value)
);
Response.Redirect("~/HandlerForRepeater.ashx?path=" + hfFilePath.Value);
}
else
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "YouCanNotDownloadAnyMore_SizeOverload", "YouCanNotDownloadAnyMore_SizeOverload();", true);
}
}
else
{
if (int.Parse(hfFileSize.Value) <= 1073741824)
//if (int.Parse(hfFileSize.Value) <= 100000)
{
DataLayer.Download.InsertRow(
int.Parse(HttpContext.Current.Session["User_ID"].ToString()),
DateTime.Now,
hfFilePath.Value,
hfFileName.Value,
hfFileSize.Value,
DateTime.Parse(hfFileCreationDate.Value)
);
Response.Redirect("~/HandlerForRepeater.ashx?path=" + hfFilePath.Value);
}
else
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "YouCanNotDownloadAnyMore_SizeOverload", "YouCanNotDownloadAnyMore_SizeOverload();", true);
}
}
}
else
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "plzLoginFirst_ForDownload", "plzLoginFirst_ForDownload();", true);
}
break;
}
default:
{
break;
}
}
}
}
我的问题是这些问题:start with ScriptManager.RegisterStartupScript
为什么这些行在更新面板内不起作用? - 没有更新面板,每件事都可以。
提前致谢
答案 0 :(得分:1)
据推测ScriptManager.RegisterStartupScript
尝试在“启动”上运行某些东西,即。页面加载或类似时。使用UpdatePanel
,服务器只是将一小撮HTML发送回客户端,该客户端将插入到已加载的页面中。
如果没有UpdatePanel
,您将发回一个全新的页面,该页面将由浏览器以正常方式加载,贯穿整个页面加载过程。
所以也许你需要在页面中已经有脚本,并处理更新面板刷新的客户端事件。不幸的是不记得如何做到这一点 - 也许这样的事情? http://msdn.microsoft.com/en-us/library/bb397499.aspx
答案 1 :(得分:1)
此问题通过此更改解决:
ScriptManager.RegisterStartupScript(this.Page, typeof(Page),
"plzLoginFirst_ForDownload", "plzLoginFirst_ForDownload();", true);