Question

I basicaly have a <asp:ImageButton> component with id "uploader" and a <p> component with id "fileInfo". upload_Click is called when the button is clicked. I have the <p> component for testing. Every time the button is clicked, the text displayed should append "x". So the first time I click it should be "x", the second "xx" and so on.

The problem i am having is that onli the first time i click the button i get "x". After that, the text stays to "x". I red on the internet that it might be a javascript error so I installed firebug, but no javascript errors pop up. I am not 100% sure I am using firebug the right way.

Can someone tell me if i'm doing something wrong?

I have the following code:

public partial class BalControls_Uploader : System.Web.UI.UserControl
{
    string attachURL = "~/Icons/attach.png";

    public string fileName = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        upload.ImageUrl = attachURL;
    }

    protected void upload_Click(object sender, ImageClickEventArgs e)
    {
        fileName += "x";
        fileInfo.InnerHtml = fileName;
    }
}
Was it helpful?

Solution

The value assigned to the variable "filename" is lost on postback.

-Define a property FileName and store the value in ViewState.

    public String FileName {
             get {
                    if(ViewState["FileName"]==null)
                       ViewState["FileName"] = String.Empty;
                  return (String) ViewState["FileName"];
              }
              set {
                  ViewState["FileName"] = value;
              }
           }
    }
//Set
this.FileName +="x";
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top