i want to store path in the database thats why i was trying to do that if is there any other solution to do that.
And i tried some suggested answers to store state also on Attach image
// Store the file path in ViewState
ViewState["FilePath"] = "~/Images/" + imageId + fileExtension;
and on page load but when the image gets upload the if (!IsPostBack) returns true and if part does not get execute so for trial i wrote that block of code in else part of thi( if (!IsPostBack)) but then
if (ViewState["FilePath"] != null) this line shows null so i did not get filepath anyways
if (!IsPostBack)
{
// Check if the file path exists in ViewState and update the Image control
if (ViewState["FilePath"] != null)
{
string filePath = ViewState["FilePath"].ToString();
Image1.ImageUrl = filePath;
}
}