Click here to Skip to main content
15,883,859 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi, i have asp.net button as

XML
<div>
                                          <div>

                                              <%-- <asp:FileUpload ID="FileUpload2" runat="server" Width="290px" />--%>
                                              <asp:FileUpload ID="FileUpload2" runat="server" Width="330px" Font-Size="12px"  />

                                          </div>
                                          <div id="divspanError"  class="strttxt" style="font-size: 12px; font-family: Calibri; width: 330px; height: 15px; text-align: left;">
                                              <%-- <span class="strttxt" style="padding-left: 0px; padding-top: 1px; color:red;font-size:14px;font-family:Calibri;" id="spanError" runat="server"></span>--%>
                                              <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
                                                  ErrorMessage="Please Select your txt file" CssClass="validationCss" ValidationGroup="I" ForeColor="Red" Font-Size="12px"
                                                  ControlToValidate="FileUpload2"></asp:RequiredFieldValidator>

                                          </div>

                                      </div>


CSS
<asp:Button ID="btnUpload" runat="server"  CssClass="trnsferpopupbtn" ValidationGroup="I" OnClick="btnUpload_Click"
                                                           Text="Upload" Style="width: 180px; height: 35px" />



the problem is that when i click on that button postback is not happening ,button click event does not fire ,when i view source the page it show me on the button onclick
javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("btnUpload", "", true, "I", "", false, false))
Posted
Comments
Gitanjali Singh 9-Jan-14 0:37am    
have you added btnUpload_Click event in code behind?
aassaahh 9-Jan-14 0:57am    
yes i have added btnUpload_Click in code behind
Sibasisjena 9-Jan-14 1:17am    
Please check my solution @aassaahh
VICK 9-Jan-14 1:03am    
have you used if(!isPostBack) on your page load ????????

Hi aassaahh,

Every thing is fine in your code. There are 2 condition
1.If you select anything in the Browse Button then if you will click on the button it will do a post back as well as call the btnUpload_Click method.
2.If you select nothing in the Browse Button then if you will click on the button it will do nothing.

It is happening because you have used a ValidationGroup="I" .

C#
protected void Page_Load(object sender, EventArgs e)
      {
          if (IsPostBack)
          {
              //This code block will when the page will be posted back.
          }
      }
 
Share this answer
 
v2
Seems to be the client validation is causing the issue. Test it by removing the validation group for the button or by using CausesValidation="false". After confirming that you can make necessary change for validation.
 
Share this answer
 
use
onclick="btnUpload_Click" on aspx page and on aspx.cs page use



C#
protected void btnUpload_Click(object sender, EventArgs e)
    {

    }
 
Share this answer
 
write onclick instead of OnClick in your below code.

in
CSS
<asp:Button ID="btnUpload" runat="server"  CssClass="trnsferpopupbtn" ValidationGroup="I" OnClick="btnUpload_Click"
                                                           Text="Upload" Style="width: 180px; height: 35px" />
 
Share this answer
 

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