在我的 aspx 页面中,我linkbtTitle
在中继器控件中有一个链接按钮:
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
<script runat="server">
protected void Buttonlink_Click(object sender, System.EventArgs e)
{
LinkButton linkbtTitle = (LinkButton)sender;
linkbtTitle.ForeColor = System.Drawing.Color.HotPink;//change color when selected
linkbtTitle.Font.Underline = true;
linkbtTitle.Font.Italic = true;
}
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<asp:LinkButton ID="linkbtTitle" runat="server" Text='<%#Eval("TITLE")%>' CommandArgument='<%#Eval("ID")%>' OnCommand="linkbtTitle_Click" OnClick="Buttonlink_Click" ></asp:LinkButton>
</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
我使用方法OnCommand="linkbtTitle_Click"
在客户端单击时自动下载附件 Linkbutton
并OnClick="Buttonlink_Click"
更改所选链接按钮的颜色。
当我建立这个页面时,附件会自动下载,但 Selected LinkButton 不会改变它的颜色。
尝试调试,没有调用函数Buttonlink_Click(),它有一条消息:Expression Statement is not assignment or call
当鼠标悬停在语句上时:... OnClick="Buttonlink_Click" ...
我想知道是否有问题linkbtTitle_Click
请看我后面的代码:
public void linkbtTitle_Click(object sender, CommandEventArgs e)
{
//auto download the attachment when selected
int mamd = Convert.ToInt32(e.CommandArgument.ToString());
string sql = "select * from MAU_DON where MA_MAU_DON="+mamd;
DataTable maudon = l.EXECUTEQUERYSQL(sql);
string attachment = dirPath["MAU_DON"].DIRECTORY + @"/" + maudon.Rows[0]["PATH"].ToString();
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.AddHeader("Content-Disposition",
"attachment; filename=" + Path.GetFileName(attachment));
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.WriteFile(attachment);
HttpContext.Current.Response.End();
}