如何将属性值从ImageButton传递给后面的代码

时间:2015-04-09 17:38:39

标签: c# asp.net

在页面加载时,我从后面的代码向ImageButton(FileUpload_result)添加一个新属性(UploadStatus)。现在点击按钮我想要检索添加的属性的值。我怎么能这样做?

public string UploadStatus = "testing";

protected void Page_Load(object sender, EventArgs e)
    { FileUpload_result.Attributes.Add("UploadStatus", UploadStatus); }


<asp:ImageButton runat="server" ID="FileUpload_result" OnClick="FileUpload_Click" ImageUrl="icon-ok.png" UploadStatus="testing" /> 

protected void FileUpload_Click(object sender, EventArgs e)
{ // How can I get the value of the added attribute UploadStatus? The value is testing in this case}

2 个答案:

答案 0 :(得分:1)

在FileUpload_Click方法中,您可以像这样访问属性。

((ImageButton)sender).Attributes["UploadStatus"]

答案 1 :(得分:0)

像FileUpload_result.Attributes [&#34;&#34; UploadStatus&#34;]之类的东西可能会得到它。 https://msdn.microsoft.com/en-us/library/kkeesb2c%28v=vs.140%29.aspx