Wednesday 15 July 2015

c# - ASP.NET/JavaScript - “Return False” Not Preventing Postback -



c# - ASP.NET/JavaScript - “Return False” Not Preventing Postback -

i have problem in web application, validation false button click event fired.

here design page:

<asp:textbox id="txtaddjournal" runat="server" /> <asp:button id="btnupload" runat="server" text="upload" onclientclick="validate();" onclick="btnupload_click"/>

here validation function:

function validate() { var journal = document.getelementbyid('<%= txtaddjournal.clientid %>').value.trim(); // alert(journal); if (journal == "" || journal == null) { alert("enter journal name"); homecoming false; } }

and code behind

protected void btnupload_click(object sender, eventargs e) { check.value = "1"; page.clientscript.registerstartupscript(this.gettype(), "callmyfunction", "load_functions()", true); //txtaddjournal.attributes.add("style", "display:block"); //btnupload.attributes.add("style", "display:block"); if (fileuploader.hasfile) { seek { string filename = path.getfilename(fileuploader.filename); //fileuploader.saveas(server.mappath("~/") + filename); // fileuploader.saveas(server.mappath("d:\\req sep16\\") + filename); oledbconnection myconnectionini = default(oledbconnection); oledbdataadapter mycommandini = default(oledbdataadapter); if (fileuploader.postedfile.filename.endswith(".xls") == false & fileuploader.postedfile.filename.endswith(".xlsx") == false) { // lbl_error.text = "upload excel format"; response.write(@"<script language='javascript'>alert('upload excel format');</script>"); return; } else { gvdetails.datasource = null; string pathtosave = httpcontext.current.server.mappath("~/uploadfiles/") + fileuploader.filename; fileuploader.postedfile.saveas(pathtosave); //strfilepath = "d:\\files\\" + fileuploader.filename; string constrini = "provider=microsoft.jet.oledb.4.0;data source=" + pathtosave + ";extended properties=excel 8.0;"; dataset ds = new dataset(); // datatable dt = new datatable(); myconnectionini = new oledbconnection(constrini); mycommandini = new oledbdataadapter("select * [sheet1$]", myconnectionini); ds = new dataset(); mycommandini.fill(ds); gvdetails.datasource = ds.tables[0]; gvdetails.databind(); } } grab (exception ex) { string msg = ex.message; } } }

please suggest me solution

you have homecoming false onclientclick:

onclientclick="return validate();" function validate() { var journal = document.getelementbyid('<%= txtaddjournal.clientid %>').value.trim(); // alert(journal); if (journal == "" || journal == null) { alert("enter journal name"); homecoming false; } homecoming true; }

javascript c# asp.net

No comments:

Post a Comment