c# - Source File 'FilePathHere' could not be opened unspecified error .NET 4.0 -
i'm new .net framework , looking @ simple contact form should submit email when button clicked , having issues.
firstly, started new project (using master pages, if matters) , changed changed name of default.aspx sendmail.aspx. then, copied , pasted code project created.
i multiple errors , warnings in mark of sendmail telling me that, example 'element' button not known element. can occur if there compilation error in web site web.config file missing. web.config file not missing. however, warning on every asp control on page
i compiler error tells me source file not opened. compiler lists file path name default.aspx.cs. name of file changed in visual studio, , yet compiler still trying read file name.
what's going on here can fix these problems in future?
markup:
<%@ page title="home page" language="c#" masterpagefile="~/site.master" autoeventwireup="true" codebehind="sendmail.aspx.cs" inherits="smtpexample._default" %> <asp:content runat="server" contentplaceholderid="headcontent"> <asp:panel id="panel1" runat="server" defaultbutton="btnsubmit"> <p> please fill following send mail.</p> <p> name: <asp:requiredfieldvalidator id="requiredfieldvalidator11" runat="server" errormessage="*" controltovalidate="yourname" validationgroup="save" /><br /> <asp:textbox id="yourname" runat="server" width="250px" /><br /> email address: <asp:requiredfieldvalidator id="requiredfieldvalidator1" runat="server" errormessage="*" controltovalidate="youremail" validationgroup="save" /><br /> <asp:textbox id="youremail" runat="server" width="250px" /> <asp:regularexpressionvalidator runat="server" id="regularexpressionvalidator23" setfocusonerror="true" text="example: username@gmail.com" controltovalidate="youremail" validationexpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" display="dynamic" validationgroup="save" /><br /> subject: <asp:requiredfieldvalidator id="requiredfieldvalidator2" runat="server" errormessage="*" controltovalidate="yoursubject" validationgroup="save" /><br /> <asp:textbox id="yoursubject" runat="server" width="400px" /><br /> question: <asp:requiredfieldvalidator id="requiredfieldvalidator3" runat="server" errormessage="*" controltovalidate="comments" validationgroup="save" /><br /> <asp:textbox id="comments" runat="server" textmode="multiline" rows="10" width="400px" /> </p> <p> <asp:button id="btnsubmit" runat="server" text="send" onclick="button1_click" validationgroup="save" /> </p> </asp:panel> <p> <asp:label id="displaymessage" runat="server" visible="false" /> </p> </asp:content> <asp:content id="content1" runat="server" contentplaceholderid="maincontent"> </asp:content> code behind:
using system; using system.collections.generic; using system.linq; using system.web; using system.web.ui; using system.web.ui.webcontrols; namespace smtpexample { public partial class _sendmail : system.web.ui.page { protected void page_load(object sender, eventargs e) { } protected void sendmail() { // gmail address send mail var fromaddress = "gmail@gmail.com"; // address email sending var toaddress = youremail.text.tostring(); //password of gmail address const string frompassword = "password"; // passing values , make email formate display string subject = yoursubject.text.tostring(); string body = "from: " + yourname.text + "\n"; body += "email: " + youremail.text + "\n"; body += "subject: " + yoursubject.text + "\n"; body += "question: \n" + comments.text + "\n"; // smtp settings var smtp = new system.net.mail.smtpclient(); { smtp.host = "smtp.gmail.com"; smtp.port = 587; smtp.enablessl = true; smtp.deliverymethod = system.net.mail.smtpdeliverymethod.network; smtp.credentials = new networkcredential(fromaddress, frompassword); smtp.timeout = 20000; } // passing values smtp object smtp.send(fromaddress, toaddress, subject, body); } protected void button1_click(object sender, eventargs e) { try { //here on button click done sendmail(); displaymessage.text = "your comments after sending mail"; displaymessage.visible = true; yoursubject.text = ""; youremail.text = ""; yourname.text = ""; comments.text = ""; } catch (exception) { } } } }
you placing elements in contentplaceholderid="headcontent" must in contentplaceholderid="maincontent"
update
i see rename default.aspx file send sendmail.aspx throe error partial classes default.aspx.cs , default.aspx.design.cs. create new page sendmail.aspx , copy code contentplaceholderid="headcontent", right click on page solution explorer click on set start page
Comments
Post a Comment