Click here to Skip to main content
15,905,612 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Below is my javascript code which clears the label message not a vaild document while choosing the file using fileuploader but the problem is it works fine in hiding the label message till it is not uploaded successfully but once if the file is uploaded again if i upload the fle by giving wrong month and year i need to show not a valid document but it is not displaying anything


<asp:FileUpload ID="FileUpload1" runat="server"  onchange="callme();" />

function callme() {
         document.getElementById("your message label id").value= "";
       }


c# code
if (month == ddlmonth.SelectedValue && year == ddlyear.SelectedValue)
               {
                   Ismatch = true;
                   //break;
               }
               else
               {
                   Ismatch = false;
                   break;
               }
           }
           if (Ismatch == true)
           {
               lblerrorMessage.Visible = false;
               lblerrorMessage.Text = "Valid Document";
           }
           else
           {
               lblerrorMessage.Text = "Not a Valid Document";
               ddlmonth.ClearSelection();
               ddlyear.ClearSelection();
               label1.Text = "";
               return;
           }


What I have tried:

I tried it but its not working because it hides the message not a valid document once it is uplaoaded successfully
Posted
Updated 23-Feb-17 4:55am
v2

Use
<input type="hidden" name="lblerrorMessage" id="lblerrorMessage" runat="server" value=""  />


I think Onchange
callme();
method should be remove. Its should be call from after Upload sucessfully

if (Ismatch == true)
           {
               lblerrorMessage.Value = "Valid Document";
               ClientScript.RegisterStartupScript(GetType(), "Javascript", "javascript:callme();", true);

           }
           else
           {
               lblerrorMessage.Value = "Not a Valid Document";
               ClientScript.RegisterStartupScript(GetType(), "Javascript", "javascript:callme(); ", true);
               return;
           }
 
Share this answer
 
v3
Comments
kav@94 23-Feb-17 6:11am    
i tried it but its not working
madhav_jain 23-Feb-17 6:32am    
give me some more information what u have tried..
kav@94 23-Feb-17 6:47am    
i need to clear my label message not a valid document while choosing the file only but it is not getting cleared
madhav_jain 23-Feb-17 6:52am    
Use


u can show alert massage like

function callme() {
alert(document.getElementById("lblerrorMessage").value);
}
kav@94 23-Feb-17 6:57am    
i did not get you can you post little clearly my requirement is i will be selecting month and year and choosing the file using file uploader if the selected month and year matches with the month and year in the sheet then data should be inserted else it should stop insertion and display as not a valid document and when i choose the file again by file uploader by selecting month and year previous label message should be disappered.below is my complete code can you suggest any solution









Select Month:<asp:DropDownList ID="ddlmonth" runat="server">
<asp:ListItem Value="0">--Select--
Select Year:<asp:DropDownList ID="ddlyear" runat="server">
<asp:ListItem Value="0">--Select--







SELECT SHEET<asp:FileUpload ID="FileUpload1" runat="server"/><asp:Button ID="btnUpload" runat="server" OnClick="btnUpload_Click" Width="130px" Height="23px" Text="UPLOAD" /> <asp:Label ID="lblerrorMessage" runat="server" ForeColor="Red">    <asp:Label ID="label1" runat="server" ForeColor="Green">    
protected void btnUpload_Click(object sender, EventArgs e)
{
//Validations for From Date,To Date and File Uploader
if (ddlmonth.SelectedValue == "0")
{
lblerrorMessage.Text = "Please Select The Month";
}
else if (ddlyear.SelectedValue == "0")
{
lblerrorMessage.Text = "Please Select The Year";
}
else if (FileUpload1.HasFile == false)
{
lblerrorMessage.Text = "Please Select A File";
}
else
{
string fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
FileUpload1.PostedFile.SaveAs(Server.MapPath("~/Files/" + fileName));
string fullpath = Path.GetFullPath(Server.MapPath("~/Files/" + fileName));
ReadExcelSheet obj = new ReadExcelSheet();
//send filepath,sheet number,selected rows to class file
DataTable dt = obj.Read(fullpath, 1);
bool Ismatch = false;

for (int i = 0; i < dt.Rows.Count; i++)
{
string date = dt.Rows[i]["Month"].ToString();
string[] date1 = date.Split('/');
string month = date1[0];
string year = date1[2];

if (month == ddlmonth.SelectedValue && year == ddlyear.SelectedValue)
{
Ismatch = true;
//break;
}
else
{
Ismatch = false;
break;
}
}
if (Ismatch == true)
{
lblerrorMessage.Visible = false;
lblerrorMessage.Text = "Valid Document";
}
else
{
lblerrorMessage.Text = "Not a Valid Document";
ddlmonth.ClearSelection();
ddlyear.ClearSelection();
label1.Text = "";
return;
}
//checking the input month and year records exists or not in DB
SqlCommand cmd = new SqlCommand("select Uploaded from TestMCount ", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable DBdt = new DataTable();
da.Fill(DBdt);
if (DBdt.Rows.Count > 0)
{
Use

input type="hidden" name="lblerrorMessage" id="lblerrorMessage" runat="server" value="" 
u can show alert massage like 

function callme() {
alert(document.getElementById("lblerrorMessage").value);
}
 
Share this answer
 
Use below code in Java script 

function callme() {           
            document.getElementById("lblerrorMessage").innerHTML="";
        }

And Change Asp:lable to     <span id="lblerrorMessage" runat="server"></span>

And .Cs use InnerText Property

 lblerrorMessage.InnerText = "Valid Document";
 
Share this answer
 
Comments
[no name] 23-Feb-17 10:58am    
Good grief. How many times do you have to answer the same question?
kav@94 23-Feb-17 11:13am    
Hi grief it is not working my requirement is i will be selecting month and year using drop down and choosing the file using file uploader if the selected month and year matches with the month and year in the sheet then data should be inserted else it should stop insertion and display as not a valid document and when i choose the file again by file uploader by selecting month and year previous label message should be disappered.Ihad posted my code in one of the comments it is the main process that happens when i click the button can you suggest any solution
kav@94 23-Feb-17 11:21am    
Hi Anandm then how should i get my requirement can you please help me out as you know my complete reuirement that is i will choose some month and year and upload the sheet using file uploader and finally i will click the button when i click the button it should check whether the month and year in the sheet matches with the month and year given by us if yes it should get inserted else it should not get inserted this process should repeat and each time when i choose the file i need to clear the previous label message after choosing the file whether it is uploaded or not i need to clear the label msg each time

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900