0
votes

I am building a search bar in my web portal on asp.net.

I have created a Search1.aspx page in which I have an Image Label having image ID as "Image1". And on the Master Page I have a search button which generates the following event-

protected void Button1_Click(object sender, EventArgs e)

    {
        Image1.ImageUrl = "~/Handler1.ashx?imgid=" + TextBox1.Text;
    }

ERROR- The error which is showing is "Image1 does not exist in current context" in Site1.Master.cs file

1
You have Image1 in Search1 and and get an error that it is not in Site1 context. That is pretty self-explanatory. I'd advice you to start more basic from tutorials/books so you understand how asp.net works.Allan S. Hansen

1 Answers

0
votes

MasterPage has reference to Page object so you can access controls from page like that:

Image img = this.Page.FindControl("Image1") as Image;
img.ImageUrl = "~/Handler1.ashx?imgid=" + TextBox1.Text;