The issue I am facing is with the ASP control FileUpload
, which always returns false
for the method FileUpload.HasFile
. Even after trying to implement a trigger, the problem persists.
Below is the function associated with the button:
protected void btnUploadFile_Clicked(object sender, EventArgs e)
{
testMethod();
}
The testMethod()
mentioned below is encountering a situation where the if statement consistently evaluates to false.
protected void testMethod()
{
if(FileUploadImage.HasFile)
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "NoDatabaseAlertMessage", "alert('it work')", true);
}
else
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "NoDatabaseAlertMessage", "alert('no work')", true);
}
}
Edit1: The HTML trigger configuration that was attempted but unsuccessful:
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Always" runat="server">
<Triggers>
<asp:PostBackTrigger ControlID="btnUploadFile" />
</Triggers>
</asp:UpdatePanel>
<asp:FileUpload ID="FileUploadImage" runat="server" />
<asp:Button ID="btnUploadFile" runat="server" Text="Upload File" class="btn btn-primary transition-3d-hover" OnClick="btnUploadFile_Clicked" />
</div>