csaexperts
asked on
Unable to send emails from ASP.NET page
Hi,
I have a ASP.NET web page, when the user updates the form and then sends Email to the user (the complete content in the form). The problem is the user is not receiving any email's. There are no errors reported by ASP.net, the email address is valid. I am completely lost why it is not working.
Any help greatly appreciated.
Thanks in advance!
I have a ASP.NET web page, when the user updates the form and then sends Email to the user (the complete content in the form). The problem is the user is not receiving any email's. There are no errors reported by ASP.net, the email address is valid. I am completely lost why it is not working.
Any help greatly appreciated.
Thanks in advance!
Here is the code
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.Net.Mail" %>
<%@ Import Namespace="System.Web.Mail" %>
<%@ Import Namespace="System.Web.UI.WebControls" %>
<%@ Import Namespace="System.Web.UI.WebControls.WebParts" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<asp:Content id="Content1" runat="server" contentplaceholderid="ContentPlaceHolder1">
<script runat="server">
protected void DetailsView1_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
{
string problemID = (string)e.Values["ProblemID"];
string userName = (string)e.Values["UserName"];
string userEmail = (string)e.Values["UserEmail"];
string userLocation = (string)e.Values["UserLocation"];
string userPhone = (string)e.Values["UserPhone"];
string ocd = (string)e.Values["ocd"];
string DepartmentName = (string)e.Values["DepartmentName"];
string UserNH = (string)e.Values["UserNH"];
string UserSSN = (string)e.Values["UserSSN"];
string IsRepresentativeInvolved = (string)e.Values["IsRepresentativeInvolved"];
string RepresentativeSSN = (string)e.Values["RepresentativeSSN"];
string RepresentativeZipCode = (string)e.Values["RepresentativeZipCode"];
string OrganizationName = (string)e.Values["OrganizationName"];
string ClaimantName = (string)e.Values["ClaimantName"];
string IsProblemQuestion = (string)e.Values["IsProblemQuestion"];
string IsComment = (string)e.Values["IsComment"];
string ProblemTitle = (string)e.Values["ProblemTitle"];
string ProblemDescription = (string)e.Values["ProblemDescription"];
string Attachment = (string)e.Values["Attachment"];
string TeamMemberName = (string)e.Values["TeamMemberName"];
string solution = (string)e.Values["solution"];
string KnowledgeBaseNotes = (string)e.Values["KnowledgeBaseNotes"];
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
message.From = new MailAddress("shruthi.andem@ssa.gov", "System E-mail");
message.To.Add(new MailAddress(userEmail, userName));
message.Subject = "Problem submission";
message.Body =
"Name: " + userName + "\n" +
"Email: " + userEmail + "\n" +
"Location: " + userLocation + "\n" +
"Phone: " + userPhone + "\n" +
"DOC: " + ocd + "\n" +
"ProblemTitle: " + ProblemTitle + "\n" +
"solution: " + solution + "\n" +
"KnowledgeBaseNotes: " + KnowledgeBaseNotes + "\n" +
"ProblemID: " + problemID;
SmtpClient client = new SmtpClient();
client.Send(message);
}
</script>
<p class="style1">
<asp:SqlDataSource id="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:HelpDeskConnectionString %>" SelectCommand="SELECT TeamMemberName, TeamMemberID FROM TeamMembers WHERE TeamMemberID > 0 ORDER BY TeamMemberName ASC">
</asp:SqlDataSource>
<span style="color: #800000"><strong>Choose A Team Member:</strong></span>
<asp:DropDownList id="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="TeamMemberName" DataValueField="TeamMemberID">
</asp:DropDownList>
<asp:SqlDataSource id="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:HelpDeskConnectionString %>" SelectCommand="SELECT PS.ProblemStatusId, TM.TeamMemberName, PROB.problemTitle, DEPT.DepartmentName, PS.ProblemStatus
FROM ProblemsUsersDeptsReps AS REPS
INNER JOIN Departments AS DEPT
ON REPS.DepartmentID = DEPT.DepartmentID
INNER JOIN Problems AS PROB
ON REPS.ProblemID = PROB.ProblemID
INNER JOIN ProblemStatus AS PS
ON REPS.ProblemsUsersDeptsRepsID = PS.ProblemsUsersDeptsRepsID
INNER JOIN TeamMembers AS TM
ON PS.TeamMemberId = TM.TeamMemberId
AND TM.TeamMemberId = @TeamMemberId
Where UPPER(ps.ProblemStatus) in ('OPEN', 'REOPEN')">
<SelectParameters>
<asp:controlparameter ControlID="DropDownList1" Name="TeamMemberId" PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
</p>
<asp:GridView id="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="ProblemStatusId" DataSourceID="SqlDataSource2" ForeColor="#333333" GridLines="None" HorizontalAlign="Center">
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<Columns>
<asp:commandfield ShowSelectButton="True">
</asp:commandfield>
<asp:boundfield DataField="ProblemStatusId" HeaderText="Problem Id" InsertVisible="False" ReadOnly="True" SortExpression="ProblemStatusId">
</asp:boundfield>
<asp:boundfield DataField="TeamMemberName" HeaderText="Team Member Name" SortExpression="TeamMemberName">
</asp:boundfield>
<asp:boundfield DataField="problemTitle" HeaderText="Subject" SortExpression="problemTitle">
</asp:boundfield>
<asp:boundfield DataField="DepartmentName" HeaderText="Title Name" SortExpression="DepartmentName">
</asp:boundfield>
<asp:boundfield DataField="ProblemStatus" HeaderText="Problem Status" SortExpression="ProblemStatus">
</asp:boundfield>
</Columns>
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
<EmptyDataTemplate>
No Problems are assigned at present. </EmptyDataTemplate>
</asp:GridView>
<br />
<br />
<div class="style1" style="text-align: left">
<asp:DetailsView id="DetailsView1" runat="server" AutoGenerateRows="False" BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px" CellPadding="2" DataKeyNames="ProblemStatusId" DataSourceID="SqlDataSource3" ForeColor="Black" GridLines="None" Height="50px" Width="100%" AllowPaging="True" OnItemInserted="DetailsView1_ItemInserted">
<FooterStyle BackColor="Tan" />
<PagerStyle BackColor="PaleGoldenrod" ForeColor="#ACA899" HorizontalAlign="Center" />
<Fields>
<asp:boundfield DataField="ProblemStatusId" HeaderText="ProblemStatusId" ReadOnly="True" InsertVisible="False" SortExpression="ProblemStatusId">
</asp:boundfield>
<asp:boundfield DataField="UserName" HeaderText="UserName" ReadOnly="True" SortExpression="UserName">
</asp:boundfield>
<asp:boundfield DataField="UserEmail" HeaderText="UserEmail" ReadOnly="True" SortExpression="UserEmail">
</asp:boundfield>
<asp:boundfield DataField="UserLocation" HeaderText="UserLocation" ReadOnly="True" SortExpression="UserLocation">
</asp:boundfield>
<asp:boundfield DataField="UserPhone" HeaderText="UserPhone" ReadOnly="True" SortExpression="UserPhone">
</asp:boundfield>
<asp:boundfield DataField="ocd" HeaderText="ocd" ReadOnly="True" SortExpression="ocd">
</asp:boundfield>
<asp:boundfield DataField="DepartmentName" HeaderText="DepartmentName" ReadOnly="True" SortExpression="DepartmentName">
</asp:boundfield>
<asp:boundfield DataField="UserNH" HeaderText="UserNH" ReadOnly="True" SortExpression="UserNH">
</asp:boundfield>
<asp:boundfield DataField="UserSSN" HeaderText="UserSSN" ReadOnly="True" SortExpression="UserSSN">
</asp:boundfield>
<asp:checkboxfield DataField="IsRepresentativeInvolved" HeaderText="IsRepresentativeInvolved" ReadOnly="True" SortExpression="IsRepresentativeInvolved">
</asp:checkboxfield>
<asp:boundfield DataField="RepresentativeSSN" HeaderText="RepresentativeSSN" ReadOnly="True" SortExpression="RepresentativeSSN">
</asp:boundfield>
<asp:boundfield DataField="RepresentativeZipCode" HeaderText="RepresentativeZipCode" ReadOnly="True" SortExpression="RepresentativeZipCode">
</asp:boundfield>
<asp:boundfield DataField="OrganizationName" HeaderText="OrganizationName" ReadOnly="True" SortExpression="OrganizationName">
</asp:boundfield>
<asp:boundfield DataField="ClaimantName" HeaderText="ClaimantName" ReadOnly="True" SortExpression="ClaimantName">
</asp:boundfield>
<asp:checkboxfield DataField="IsProblemQuestion" HeaderText="IsProblemQuestion" ReadOnly="True" SortExpression="IsProblemQuestion">
</asp:checkboxfield>
<asp:checkboxfield DataField="IsComment" HeaderText="IsComment" ReadOnly="True" SortExpression="IsComment">
</asp:checkboxfield>
<asp:boundfield DataField="ProblemTitle" HeaderText="ProblemTitle" ReadOnly="True" SortExpression="ProblemTitle">
</asp:boundfield>
<asp:boundfield DataField="ProblemDescription" HeaderText="ProblemDescription" ReadOnly="True" SortExpression="ProblemDescription">
</asp:boundfield>
<asp:boundfield DataField="Attachment" HeaderText="Attachment" ReadOnly="True" SortExpression="Attachment">
</asp:boundfield>
<asp:boundfield DataField="TeamMemberName" HeaderText="TeamMemberName" ReadOnly="True" SortExpression="TeamMemberName">
</asp:boundfield>
<asp:boundfield DataField="solution" HeaderText="solution" SortExpression="solution">
</asp:boundfield>
<asp:boundfield DataField="KnowledgeBaseNotes" HeaderText="KnowledgeBaseNotes" SortExpression="KnowledgeBaseNotes">
</asp:boundfield>
<asp:commandfield ShowEditButton="True">
</asp:commandfield>
</Fields>
<HeaderStyle BackColor="Tan" Font-Bold="True" />
<EditRowStyle BackColor="PaleGoldenrod" ForeColor="Black" />
<AlternatingRowStyle BackColor="PaleGoldenrod" />
</asp:DetailsView>
</div>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:HelpDeskConnectionString %>" SelectCommand="GetInformationForProblemStatusIdforAdmin" SelectCommandType="StoredProcedure" UpdateCommand="InsertOrUpdateAndClosedPSandKB" UpdateCommandType="StoredProcedure">
<SelectParameters>
<asp:controlparameter ControlID="GridView1" Name="problemStatusId" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:parameter Name="KnowledgeBaseNotes" Type="String" />
<asp:parameter Direction="InputOutput" Name="problem_solution_id" Type="Int32" />
<asp:parameter Name="ProblemStatusID" Type="Int32" />
<asp:parameter Name="Solution" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
Could it be that your exchange server is blocking your emails, treating them as SPAM?
I don't see where you're actually setting the mailserver. Unless you specify it in this file OR in your local app web.config file you may have some unpredictable behavior.
Two questions:
1. Is this a shared hosting environment that you have no control over?
2. Is the SMTP server you're trying to use "localhost"? If not the code above definitely won't send a message.
Two questions:
1. Is this a shared hosting environment that you have no control over?
2. Is the SMTP server you're trying to use "localhost"? If not the code above definitely won't send a message.
I don't see SMTP server settings in your code. You may need to setup at lest the following parameters necessary for SMTP connection:
smtpClient.Host = SmtpServer;
smtpClient.Port = SmtpPort;
smtpClient.Credentials = new NetworkCredential(SmtpUser Name, SmtpUserPass);
or set message headers
message.Headers.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", SmtpAuthProtocol.ToString( ));
message.Headers.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", SmtpUserName);
message.Headers.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", SmtpUserPass);
smtpClient.Host = SmtpServer;
smtpClient.Port = SmtpPort;
smtpClient.Credentials = new NetworkCredential(SmtpUser
or set message headers
message.Headers.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", SmtpAuthProtocol.ToString(
message.Headers.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", SmtpUserName);
message.Headers.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", SmtpUserPass);
ASKER
Thanks for the reply to all
azarc3,
I sepecified mailserver settings in web.config.
Reg<system.net>
<mailSettings>
<smtp>
<network host="**********"
port="25"/>
</smtp>
</mailSettings>
</system.net>
Regarding your questions:
1. Is this a shared hosting environment that you have no control over? - No its not a Shared hosting Environment and I dont have any control over it.
2. Is the SMTP server you're trying to use "localhost"? If not the code above definitely won't send a message - This SMTP server is not a "localhost". if this code doesnt work, then can I have the code which works. I am new to asp.net programming
azarc3,
I sepecified mailserver settings in web.config.
Reg<system.net>
<mailSettings>
<smtp>
<network host="**********"
port="25"/>
</smtp>
</mailSettings>
</system.net>
Regarding your questions:
1. Is this a shared hosting environment that you have no control over? - No its not a Shared hosting Environment and I dont have any control over it.
2. Is the SMTP server you're trying to use "localhost"? If not the code above definitely won't send a message - This SMTP server is not a "localhost". if this code doesnt work, then can I have the code which works. I am new to asp.net programming
csaexperts,
Let me clarify: your code *WOULD* work in certain situations, but not in most scenarios...
... for instance, if the SMTP server that the Web Server uses has no alias known to the Web Server as "localhost" then your code *probably* wouldn't work because there's no given that default SMTP server was set in the root level web.config file.
The code you've listed should work *IF* the SMTP server you've hidden above is an open relay and doesn't require a message send request to provide credentials. If it does require credentials then you'll want to update your network key to the following (which should get you going):
Let me clarify: your code *WOULD* work in certain situations, but not in most scenarios...
... for instance, if the SMTP server that the Web Server uses has no alias known to the Web Server as "localhost" then your code *probably* wouldn't work because there's no given that default SMTP server was set in the root level web.config file.
The code you've listed should work *IF* the SMTP server you've hidden above is an open relay and doesn't require a message send request to provide credentials. If it does require credentials then you'll want to update your network key to the following (which should get you going):
<system.net>
<mailSettings>
<smtp from="test@foo.com">
<network host="{smtp server address}" port="25" userName="{email account's smtp user name}" password="{email account's smtp password}" defaultCredentials="true" />
</smtp>
</mailSettings>
</system.net>
ASKER
azarc3,
After adding credentials , I tried to execute the page on the server, I am still having issues with it
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.
After adding credentials , I tried to execute the page on the server, I am still having issues with it
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.
You need to update your web.config file to display the actual error. Do the following:
1. Update the system.web/compliation key and set the "debug" attribute to "true".
2. Update the system.web/customErrors key and set the "mode" attribute to "Off".
Examples are below.
1. Update the system.web/compliation key and set the "debug" attribute to "true".
2. Update the system.web/customErrors key and set the "mode" attribute to "Off".
Examples are below.
<configuration>
<system.web>
...
<compilation debug="true">
...
<customErrors mode="Off" />
...
</system.web>
</configuration>
ASKER
azarc3,
I already did that, I am still getting the same issue
<configuration>
<!-- Database settings
This section sets the connection for Database to the application -->
<connectionStrings>
<add name="HelpDeskConnectionSt ring" connectionString="Data Source=@@@;Initial Catalog=##k;Persist Security Info=True;User ID=###;Password=##3k" providerName="System.Data. SqlClient" />
</connectionStrings>
<system.net>
<mailSettings>
<smtp>
<network host="#####"
port="25" defaultCredentials="true"/ >
</smtp>
</mailSettings>
</system.net>
<system.web>
<httpHandlers>
<add path="Reserved.ReportViewe rWebContro l.axd" verb="*" type="Microsoft.Reporting. WebForms.H ttpHandler , Microsoft.ReportViewer.Web Forms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d 50a3a" validate="false"/>
</httpHandlers>
<compilation debug="true">
<customErrors mode="Off" />
<buildProviders>
<add extension=".rdlc" type="Microsoft.Reporting. RdlBuildPr ovider, Microsoft.ReportViewer.Com mon, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d 50a3a"/>
</buildProviders>
<assemblies>
<add assembly="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c56193 4e089"/>
<add assembly="System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D 50A3A"/>
<add assembly="System.Configura tion, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D 50A3A"/>
<add assembly="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C56193 4E089"/>
<add assembly="System.Web.Servi ces, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D 50A3A"/>
<add assembly="Microsoft.Report Viewer.Com mon, Version=8.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D 50A3A"/>
<add assembly="Microsoft.Report Viewer.Web Forms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D 50A3A"/>
<add assembly="Microsoft.Report Viewer.Win Forms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D 50A3A"/>
<add assembly="System.Web.Regul arExpressi ons, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D 50A3A"/>
<add assembly="System.Windows.F orms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C56193 4E089"/></ assemblies ></compila tion></sys tem.web></ configurat ion>
I already did that, I am still getting the same issue
<configuration>
<!-- Database settings
This section sets the connection for Database to the application -->
<connectionStrings>
<add name="HelpDeskConnectionSt
</connectionStrings>
<system.net>
<mailSettings>
<smtp>
<network host="#####"
port="25" defaultCredentials="true"/
</smtp>
</mailSettings>
</system.net>
<system.web>
<httpHandlers>
<add path="Reserved.ReportViewe
</httpHandlers>
<compilation debug="true">
<customErrors mode="Off" />
<buildProviders>
<add extension=".rdlc" type="Microsoft.Reporting.
</buildProviders>
<assemblies>
<add assembly="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c56193
<add assembly="System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D
<add assembly="System.Configura
<add assembly="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C56193
<add assembly="System.Web.Servi
<add assembly="Microsoft.Report
<add assembly="Microsoft.Report
<add assembly="Microsoft.Report
<add assembly="System.Web.Regul
<add assembly="System.Windows.F
Can you post the URL or attach the code so I can see the error?
... uh, I suggest a temporary URL that will be changed once you get things squared away. ;)
Make sure you use the correct case needs to be "Off"
have you tried putting the host detail into the code, so
client = New SmtpClient("mail.yourserve r.com");
and the credentials there too?
have you tried putting the host detail into the code, so
client = New SmtpClient("mail.yourserve
and the credentials there too?
It sounds like trying to see the error on the server is getting to be an obstacle and may not actually be the problem... and that you probably need to run debug this on your local machine... is that possible? You don't have to change your connection strings... just hit F5 on if the code is open in Visual Studio.
ASKER
azarc3,
Here is the complete code:
<%@ Page Language="C#" masterpagefile="../Master/ Master.mas ter" title="Email Response System" Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.Net.Mail " %>
<%@ Import Namespace="System.Web.Mail " %>
<%@ Import Namespace="System.Web.UI.W ebControls " %>
<%@ Import Namespace="System.Web.UI.W ebControls .WebParts" %>
<%@ Import Namespace="System.Data.Sql Client" %>
<asp:Content id="Content1" runat="server" contentplaceholderid="Cont entPlaceHo lder1">
<script runat="server">
protected void DetailsView1_ItemInserted( object sender, DetailsViewInsertedEventAr gs e)
{
string problemID = (string)e.Values["ProblemI D"];
string userName = (string)e.Values["UserName "];
string userEmail = (string)e.Values["UserEmai l"];
string userLocation = (string)e.Values["UserLoca tion"];
string userPhone = (string)e.Values["UserPhon e"];
string ocd = (string)e.Values["ocd"];
string DepartmentName = (string)e.Values["Departme ntName"];
string UserNH = (string)e.Values["UserNH"] ;
string UserSSN = (string)e.Values["UserSSN" ];
string IsRepresentativeInvolved = (string)e.Values["IsRepres entativeIn volved"];
string RepresentativeSSN = (string)e.Values["Represen tativeSSN" ];
string RepresentativeZipCode = (string)e.Values["Represen tativeZipC ode"];
string OrganizationName = (string)e.Values["Organiza tionName"] ;
string ClaimantName = (string)e.Values["Claimant Name"];
string IsProblemQuestion = (string)e.Values["IsProble mQuestion" ];
string IsComment = (string)e.Values["IsCommen t"];
string ProblemTitle = (string)e.Values["ProblemT itle"];
string ProblemDescription = (string)e.Values["ProblemD escription "];
string Attachment = (string)e.Values["Attachme nt"];
string TeamMemberName = (string)e.Values["TeamMemb erName"];
string solution = (string)e.Values["solution "];
string KnowledgeBaseNotes = (string)e.Values["Knowledg eBaseNotes "];
System.Net.Mail.MailMessag e message = new System.Net.Mail.MailMessag e();
message.From = new MailAddress(sam@soc.com, "System E-mail");
message.To.Add(new MailAddress(userEmail, userName));
message.Subject = "Problem submission";
message.Body =
"Name: " + userName + "\n" +
"Email: " + userEmail + "\n" +
"Location: " + userLocation + "\n" +
"Phone: " + userPhone + "\n" +
"DOC: " + ocd + "\n" +
"ProblemTitle: " + ProblemTitle + "\n" +
"solution: " + solution + "\n" +
"KnowledgeBaseNotes: " + KnowledgeBaseNotes + "\n" +
"ProblemID: " + problemID;
smtpClient.Host = "!!!";
smtpClient.Port = "25";
smtpClient.Credentials = new NetworkCredential(SmtpUser Name, SmtpUserPass);
client.EnableSsl = true;
client.Send(message);
}
</script>
<p class="style1">
<asp:SqlDataSource id="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:HelpDesk Connection String %>" SelectCommand="SELECT TeamMemberName, TeamMemberID FROM TeamMembers WHERE TeamMemberID > 0 ORDER BY TeamMemberName ASC">
</asp:SqlDataSource>
<span style="color: #800000"><strong>Choose A Team Member:</strong></span>
<asp:DropDownList id="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSourc e1" DataTextField="TeamMemberN ame" DataValueField="TeamMember ID">
</asp:DropDownList>
<asp:SqlDataSource id="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:HelpDesk Connection String %>" SelectCommand="SELECT PS.ProblemStatusId, TM.TeamMemberName, PROB.problemTitle, DEPT.DepartmentName, PS.ProblemStatus
FROM ProblemsUsersDeptsReps AS REPS
INNER JOIN Departments AS DEPT
ON REPS.DepartmentID = DEPT.DepartmentID
INNER JOIN Problems AS PROB
ON REPS.ProblemID = PROB.ProblemID
INNER JOIN ProblemStatus AS PS
ON REPS.ProblemsUsersDeptsRep sID = PS.ProblemsUsersDeptsRepsI D
INNER JOIN TeamMembers AS TM
ON PS.TeamMemberId = TM.TeamMemberId
AND TM.TeamMemberId = @TeamMemberId
Where UPPER(ps.ProblemStatus) in ('OPEN', 'REOPEN')">
<SelectParameters>
<asp:controlparameter ControlID="DropDownList1" Name="TeamMemberId" PropertyName="SelectedValu e" />
</SelectParameters>
</asp:SqlDataSource>
</p>
<asp:GridView id="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False " CellPadding="4" DataKeyNames="ProblemStatu sId" DataSourceID="SqlDataSourc e2" ForeColor="#333333" GridLines="None" HorizontalAlign="Center">
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<Columns>
<asp:commandfield ShowSelectButton="True">
</asp:commandfield>
<asp:boundfield DataField="ProblemStatusId " HeaderText="Problem Id" InsertVisible="False" ReadOnly="True" SortExpression="ProblemSta tusId">
</asp:boundfield>
<asp:boundfield DataField="TeamMemberName" HeaderText="Team Member Name" SortExpression="TeamMember Name">
</asp:boundfield>
<asp:boundfield DataField="problemTitle" HeaderText="Subject" SortExpression="problemTit le">
</asp:boundfield>
<asp:boundfield DataField="DepartmentName" HeaderText="Title Name" SortExpression="Department Name">
</asp:boundfield>
<asp:boundfield DataField="ProblemStatus" HeaderText="Problem Status" SortExpression="ProblemSta tus">
</asp:boundfield>
</Columns>
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
<EmptyDataTemplate>
No Problems are assigned at present. </EmptyDataTemplate>
</asp:GridView>
<br />
<br />
<div class="style1" style="text-align: left">
<asp:DetailsView id="DetailsView1" runat="server" AutoGenerateRows="False" BackColor="LightGoldenrodY ellow" BorderColor="Tan" BorderWidth="1px" CellPadding="2" DataKeyNames="ProblemStatu sId" DataSourceID="SqlDataSourc e3" ForeColor="Black" GridLines="None" Height="50px" Width="100%" AllowPaging="True" OnItemInserted="DetailsVie w1_ItemIns erted">
<FooterStyle BackColor="Tan" />
<PagerStyle BackColor="PaleGoldenrod" ForeColor="#ACA899" HorizontalAlign="Center" />
<Fields>
<asp:boundfield DataField="ProblemStatusId " HeaderText="ProblemStatusI d" ReadOnly="True" InsertVisible="False" SortExpression="ProblemSta tusId">
</asp:boundfield>
<asp:boundfield DataField="UserName" HeaderText="UserName" ReadOnly="True" SortExpression="UserName">
</asp:boundfield>
<asp:boundfield DataField="UserEmail" HeaderText="UserEmail" ReadOnly="True" SortExpression="UserEmail" >
</asp:boundfield>
<asp:boundfield DataField="UserLocation" HeaderText="UserLocation" ReadOnly="True" SortExpression="UserLocati on">
</asp:boundfield>
<asp:boundfield DataField="UserPhone" HeaderText="UserPhone" ReadOnly="True" SortExpression="UserPhone" >
</asp:boundfield>
<asp:boundfield DataField="ocd" HeaderText="ocd" ReadOnly="True" SortExpression="ocd">
</asp:boundfield>
<asp:boundfield DataField="DepartmentName" HeaderText="DepartmentName " ReadOnly="True" SortExpression="Department Name">
</asp:boundfield>
<asp:boundfield DataField="UserNH" HeaderText="UserNH" ReadOnly="True" SortExpression="UserNH">
</asp:boundfield>
<asp:boundfield DataField="UserSSN" HeaderText="UserSSN" ReadOnly="True" SortExpression="UserSSN">
</asp:boundfield>
<asp:checkboxfield DataField="IsRepresentativ eInvolved" HeaderText="IsRepresentati veInvolved " ReadOnly="True" SortExpression="IsRepresen tativeInvo lved">
</asp:checkboxfield>
<asp:boundfield DataField="RepresentativeS SN" HeaderText="Representative SSN" ReadOnly="True" SortExpression="Representa tiveSSN">
</asp:boundfield>
<asp:boundfield DataField="RepresentativeZ ipCode" HeaderText="Representative ZipCode" ReadOnly="True" SortExpression="Representa tiveZipCod e">
</asp:boundfield>
<asp:boundfield DataField="OrganizationNam e" HeaderText="OrganizationNa me" ReadOnly="True" SortExpression="Organizati onName">
</asp:boundfield>
<asp:boundfield DataField="ClaimantName" HeaderText="ClaimantName" ReadOnly="True" SortExpression="ClaimantNa me">
</asp:boundfield>
<asp:checkboxfield DataField="IsProblemQuesti on" HeaderText="IsProblemQuest ion" ReadOnly="True" SortExpression="IsProblemQ uestion">
</asp:checkboxfield>
<asp:checkboxfield DataField="IsComment" HeaderText="IsComment" ReadOnly="True" SortExpression="IsComment" >
</asp:checkboxfield>
<asp:boundfield DataField="ProblemTitle" HeaderText="ProblemTitle" ReadOnly="True" SortExpression="ProblemTit le">
</asp:boundfield>
<asp:boundfield DataField="ProblemDescript ion" HeaderText="ProblemDescrip tion" ReadOnly="True" SortExpression="ProblemDes cription">
</asp:boundfield>
<asp:boundfield DataField="Attachment" HeaderText="Attachment" ReadOnly="True" SortExpression="Attachment ">
</asp:boundfield>
<asp:boundfield DataField="TeamMemberName" HeaderText="TeamMemberName " ReadOnly="True" SortExpression="TeamMember Name">
</asp:boundfield>
<asp:boundfield DataField="solution" HeaderText="solution" SortExpression="solution">
</asp:boundfield>
<asp:boundfield DataField="KnowledgeBaseNo tes" HeaderText="KnowledgeBaseN otes" SortExpression="KnowledgeB aseNotes">
</asp:boundfield>
<asp:commandfield ShowEditButton="True">
</asp:commandfield>
</Fields>
<HeaderStyle BackColor="Tan" Font-Bold="True" />
<EditRowStyle BackColor="PaleGoldenrod" ForeColor="Black" />
<AlternatingRowStyle BackColor="PaleGoldenrod" />
</asp:DetailsView>
</div>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:HelpDesk Connection String %>" SelectCommand="GetInformat ionForProb lemStatusI dforAdmin" SelectCommandType="StoredP rocedure" UpdateCommand="InsertOrUpd ateAndClos edPSandKB" UpdateCommandType="StoredP rocedure">
<SelectParameters>
<asp:controlparameter ControlID="GridView1" Name="problemStatusId" PropertyName="SelectedValu e" Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:parameter Name="KnowledgeBaseNotes" Type="String" />
<asp:parameter Direction="InputOutput" Name="problem_solution_id" Type="Int32" />
<asp:parameter Name="ProblemStatusID" Type="Int32" />
<asp:parameter Name="Solution" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
<br />
<div class="style1" style="text-align: left">
</div>
<p class="style1"><br />
</p>
</asp:Content>
<asp:Content id="Content2" runat="server" contentplaceholderid="head ">
<h4 class="style1" style="color: #800000">Please Select a Team Member
from the List to Edit the Tickets.</h4>
</asp:Content>
and here is the error message:
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.
Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".
<!-- Web.Config Configuration File --> <configuration> <system.web> <customErrors mode="Off"/> </system.web> </configuration>
Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL.
<!-- Web.Config Configuration File --> <configuration> <system.web> <customErrors mode="RemoteOnly" defaultRedirect="mycustomp age.htm"/> </system.web> </configuration>
Here is the complete code:
<%@ Page Language="C#" masterpagefile="../Master/
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.Net.Mail
<%@ Import Namespace="System.Web.Mail
<%@ Import Namespace="System.Web.UI.W
<%@ Import Namespace="System.Web.UI.W
<%@ Import Namespace="System.Data.Sql
<asp:Content id="Content1" runat="server" contentplaceholderid="Cont
<script runat="server">
protected void DetailsView1_ItemInserted(
{
string problemID = (string)e.Values["ProblemI
string userName = (string)e.Values["UserName
string userEmail = (string)e.Values["UserEmai
string userLocation = (string)e.Values["UserLoca
string userPhone = (string)e.Values["UserPhon
string ocd = (string)e.Values["ocd"];
string DepartmentName = (string)e.Values["Departme
string UserNH = (string)e.Values["UserNH"]
string UserSSN = (string)e.Values["UserSSN"
string IsRepresentativeInvolved = (string)e.Values["IsRepres
string RepresentativeSSN = (string)e.Values["Represen
string RepresentativeZipCode = (string)e.Values["Represen
string OrganizationName = (string)e.Values["Organiza
string ClaimantName = (string)e.Values["Claimant
string IsProblemQuestion = (string)e.Values["IsProble
string IsComment = (string)e.Values["IsCommen
string ProblemTitle = (string)e.Values["ProblemT
string ProblemDescription = (string)e.Values["ProblemD
string Attachment = (string)e.Values["Attachme
string TeamMemberName = (string)e.Values["TeamMemb
string solution = (string)e.Values["solution
string KnowledgeBaseNotes = (string)e.Values["Knowledg
System.Net.Mail.MailMessag
message.From = new MailAddress(sam@soc.com, "System E-mail");
message.To.Add(new MailAddress(userEmail, userName));
message.Subject = "Problem submission";
message.Body =
"Name: " + userName + "\n" +
"Email: " + userEmail + "\n" +
"Location: " + userLocation + "\n" +
"Phone: " + userPhone + "\n" +
"DOC: " + ocd + "\n" +
"ProblemTitle: " + ProblemTitle + "\n" +
"solution: " + solution + "\n" +
"KnowledgeBaseNotes: " + KnowledgeBaseNotes + "\n" +
"ProblemID: " + problemID;
smtpClient.Host = "!!!";
smtpClient.Port = "25";
smtpClient.Credentials = new NetworkCredential(SmtpUser
client.EnableSsl = true;
client.Send(message);
}
</script>
<p class="style1">
<asp:SqlDataSource id="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:HelpDesk
</asp:SqlDataSource>
<span style="color: #800000"><strong>Choose A Team Member:</strong></span>
<asp:DropDownList id="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSourc
</asp:DropDownList>
<asp:SqlDataSource id="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:HelpDesk
FROM ProblemsUsersDeptsReps AS REPS
INNER JOIN Departments AS DEPT
ON REPS.DepartmentID = DEPT.DepartmentID
INNER JOIN Problems AS PROB
ON REPS.ProblemID = PROB.ProblemID
INNER JOIN ProblemStatus AS PS
ON REPS.ProblemsUsersDeptsRep
INNER JOIN TeamMembers AS TM
ON PS.TeamMemberId = TM.TeamMemberId
AND TM.TeamMemberId = @TeamMemberId
Where UPPER(ps.ProblemStatus) in ('OPEN', 'REOPEN')">
<SelectParameters>
<asp:controlparameter ControlID="DropDownList1" Name="TeamMemberId" PropertyName="SelectedValu
</SelectParameters>
</asp:SqlDataSource>
</p>
<asp:GridView id="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<Columns>
<asp:commandfield ShowSelectButton="True">
</asp:commandfield>
<asp:boundfield DataField="ProblemStatusId
</asp:boundfield>
<asp:boundfield DataField="TeamMemberName"
</asp:boundfield>
<asp:boundfield DataField="problemTitle" HeaderText="Subject" SortExpression="problemTit
</asp:boundfield>
<asp:boundfield DataField="DepartmentName"
</asp:boundfield>
<asp:boundfield DataField="ProblemStatus" HeaderText="Problem Status" SortExpression="ProblemSta
</asp:boundfield>
</Columns>
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
<EmptyDataTemplate>
No Problems are assigned at present. </EmptyDataTemplate>
</asp:GridView>
<br />
<br />
<div class="style1" style="text-align: left">
<asp:DetailsView id="DetailsView1" runat="server" AutoGenerateRows="False" BackColor="LightGoldenrodY
<FooterStyle BackColor="Tan" />
<PagerStyle BackColor="PaleGoldenrod" ForeColor="#ACA899" HorizontalAlign="Center" />
<Fields>
<asp:boundfield DataField="ProblemStatusId
</asp:boundfield>
<asp:boundfield DataField="UserName" HeaderText="UserName" ReadOnly="True" SortExpression="UserName">
</asp:boundfield>
<asp:boundfield DataField="UserEmail" HeaderText="UserEmail" ReadOnly="True" SortExpression="UserEmail"
</asp:boundfield>
<asp:boundfield DataField="UserLocation" HeaderText="UserLocation" ReadOnly="True" SortExpression="UserLocati
</asp:boundfield>
<asp:boundfield DataField="UserPhone" HeaderText="UserPhone" ReadOnly="True" SortExpression="UserPhone"
</asp:boundfield>
<asp:boundfield DataField="ocd" HeaderText="ocd" ReadOnly="True" SortExpression="ocd">
</asp:boundfield>
<asp:boundfield DataField="DepartmentName"
</asp:boundfield>
<asp:boundfield DataField="UserNH" HeaderText="UserNH" ReadOnly="True" SortExpression="UserNH">
</asp:boundfield>
<asp:boundfield DataField="UserSSN" HeaderText="UserSSN" ReadOnly="True" SortExpression="UserSSN">
</asp:boundfield>
<asp:checkboxfield DataField="IsRepresentativ
</asp:checkboxfield>
<asp:boundfield DataField="RepresentativeS
</asp:boundfield>
<asp:boundfield DataField="RepresentativeZ
</asp:boundfield>
<asp:boundfield DataField="OrganizationNam
</asp:boundfield>
<asp:boundfield DataField="ClaimantName" HeaderText="ClaimantName" ReadOnly="True" SortExpression="ClaimantNa
</asp:boundfield>
<asp:checkboxfield DataField="IsProblemQuesti
</asp:checkboxfield>
<asp:checkboxfield DataField="IsComment" HeaderText="IsComment" ReadOnly="True" SortExpression="IsComment"
</asp:checkboxfield>
<asp:boundfield DataField="ProblemTitle" HeaderText="ProblemTitle" ReadOnly="True" SortExpression="ProblemTit
</asp:boundfield>
<asp:boundfield DataField="ProblemDescript
</asp:boundfield>
<asp:boundfield DataField="Attachment" HeaderText="Attachment" ReadOnly="True" SortExpression="Attachment
</asp:boundfield>
<asp:boundfield DataField="TeamMemberName"
</asp:boundfield>
<asp:boundfield DataField="solution" HeaderText="solution" SortExpression="solution">
</asp:boundfield>
<asp:boundfield DataField="KnowledgeBaseNo
</asp:boundfield>
<asp:commandfield ShowEditButton="True">
</asp:commandfield>
</Fields>
<HeaderStyle BackColor="Tan" Font-Bold="True" />
<EditRowStyle BackColor="PaleGoldenrod" ForeColor="Black" />
<AlternatingRowStyle BackColor="PaleGoldenrod" />
</asp:DetailsView>
</div>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:HelpDesk
<SelectParameters>
<asp:controlparameter ControlID="GridView1" Name="problemStatusId" PropertyName="SelectedValu
</SelectParameters>
<UpdateParameters>
<asp:parameter Name="KnowledgeBaseNotes" Type="String" />
<asp:parameter Direction="InputOutput" Name="problem_solution_id"
<asp:parameter Name="ProblemStatusID" Type="Int32" />
<asp:parameter Name="Solution" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
<br />
<div class="style1" style="text-align: left">
</div>
<p class="style1"><br />
</p>
</asp:Content>
<asp:Content id="Content2" runat="server" contentplaceholderid="head
<h4 class="style1" style="color: #800000">Please Select a Team Member
from the List to Edit the Tickets.</h4>
</asp:Content>
and here is the error message:
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.
Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".
<!-- Web.Config Configuration File --> <configuration> <system.web> <customErrors mode="Off"/> </system.web> </configuration>
Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL.
<!-- Web.Config Configuration File --> <configuration> <system.web> <customErrors mode="RemoteOnly" defaultRedirect="mycustomp
Whatever the error is, clearly it is causing problems.
From your code i have a few questions:
1) Where do you declare and instantiate the smtpClient object:
smtpClient.Host = "!!!";
smtpClient.Port = "25";
smtpClient.Credentials = new NetworkCredential(SmtpUser Name, SmtpUserPass);
client.EnableSsl = true;
client.Send(message);
You have used "smtpClient" and just "client", maybe this is incorrectly pasted code to the forum, but it is incorrect. (ill assume the !!! is massaged for privacy - sensible!)
2) if you can't get the error to be shown, some shared hosting prevent some settings being overridden, who knows why/if this is one, but you could put a big try catch block around the whole thing and on error, write the exception to the page (don't rethrow the exception) Then post what the actual error is.
Hope this helps
From your code i have a few questions:
1) Where do you declare and instantiate the smtpClient object:
smtpClient.Host = "!!!";
smtpClient.Port = "25";
smtpClient.Credentials = new NetworkCredential(SmtpUser
client.EnableSsl = true;
client.Send(message);
You have used "smtpClient" and just "client", maybe this is incorrectly pasted code to the forum, but it is incorrect. (ill assume the !!! is massaged for privacy - sensible!)
2) if you can't get the error to be shown, some shared hosting prevent some settings being overridden, who knows why/if this is one, but you could put a big try catch block around the whole thing and on error, write the exception to the page (don't rethrow the exception) Then post what the actual error is.
Hope this helps
ASKER
azarc3,
after debugging the code, here is the error message i have received
It is an error to use a section registered as allowDefinition='MachineTo Applicatio n' beyond application level. This error can be caused by a virtual directory not ebing configured as an application to IIS
after debugging the code, here is the error message i have received
It is an error to use a section registered as allowDefinition='MachineTo
Here's part of the problem; you have two customError keys in your web.config file. you should get rid of the first one.
Change this one to:
Change this one to:
<!-- *** CHANGE FROM *** -->
<configuration>
<system.web>
<customErrors mode="ReadOnly" defaultRedirect="mycustompage.htm"/>
</system.web>
</configuration>
<!-- *** CHANGE TO *** -->
<configuration>
<system.web>
<customErrors mode="Off" defaultRedirect="mycustompage.htm"/>
</system.web>
</configuration>
My fault; thought that last part was part of your web.config file... disregard my last comment... be back in a bit with a suggestion...
See this link: http://forums.asp.net/t/1031775.aspx
Specifically, the part about having a backup of the website in the project without excluding it from the active project?
You're definitely getting a conflict in your configuration... the problem is that we need to determine if the conflict is INSIDE your site or BETWEEN your site and the server's root-level config.
Specifically, the part about having a backup of the website in the project without excluding it from the active project?
You're definitely getting a conflict in your configuration... the problem is that we need to determine if the conflict is INSIDE your site or BETWEEN your site and the server's root-level config.
ASKER
azarc3,
Regarding your previous message, For security purpose I havent mentioned the SMTP server name and other things. I checked them again and they are absolutely right SMTP address and email address....
Before you replied to me I checked my directory, i found duplicate web.config which I deleted. Now I am not receiving any error message but still I am not able to send any Email to the User after updating/inserting my records.
I still have the same issue :(
Regarding your previous message, For security purpose I havent mentioned the SMTP server name and other things. I checked them again and they are absolutely right SMTP address and email address....
Before you replied to me I checked my directory, i found duplicate web.config which I deleted. Now I am not receiving any error message but still I am not able to send any Email to the User after updating/inserting my records.
I still have the same issue :(
Well, at least we're moving in the right direction (we know what's NOT wrong, right?).
Are you certain you're hitting the code that sends the message? Specifically, when you place a breakpoint at the following line: client.Send(message); --> I don't think you are...
I just took a MUCH closer look at this 'cause something smelled fishy, and I noticed that the SqlDataSourceID for DetailsView1 is SqlDataSource3. However, there's not InsertCommand attribute declared on SqlDataSource3. By some black box magic the INSERT may actually be happening with the InsertOrUpdateAndClosedPSa ndKB() method that's declared for SqlDataSource3, but it looks like the DetailsView1_ItemInserted event is never being fired. I think if you add the following InsertCommand attribute to SqlDataSource3 it should at least get down into the necessary method.
Are you certain you're hitting the code that sends the message? Specifically, when you place a breakpoint at the following line: client.Send(message); --> I don't think you are...
I just took a MUCH closer look at this 'cause something smelled fishy, and I noticed that the SqlDataSourceID for DetailsView1 is SqlDataSource3. However, there's not InsertCommand attribute declared on SqlDataSource3. By some black box magic the INSERT may actually be happening with the InsertOrUpdateAndClosedPSa
InsertCommand="InsertOrUpdateAndClosedPSandKB" InsertCommandType="StoredProcedure"
ASKER
azarc3,
For this particular web page I cannot use insert, I am using Update
UpdateCommand="InsertOrUpd ateAndClos edPSandKB" UpdateCommandType="StoredP rocedure"
Even in my SP....I am using Update(if the record is existing) and Insert(If its a new record).
In my detailview do i need to change onItemInserted to OnItemUpdated?
But if i try to change to OnItemUpdated I am getting error message
CS0117: 'System.Web.UI.WebControls .DetailsVi ewUpdatedE ventArgs' does not contain a definition for 'Values'
Line 12: protected void DetailsView1_ItemUpdated(o bject sender, DetailsViewUpdatedEventArg s e)
Line 13: {
Line 14: string problemID = (string)e.Values["ProblemI D"];
Line 15: string userName = (string)e.Values["UserName "];
Line 16: string userEmail = (string)e.Values["UserEmai l"];
For this particular web page I cannot use insert, I am using Update
UpdateCommand="InsertOrUpd
Even in my SP....I am using Update(if the record is existing) and Insert(If its a new record).
In my detailview do i need to change onItemInserted to OnItemUpdated?
But if i try to change to OnItemUpdated I am getting error message
CS0117: 'System.Web.UI.WebControls
Line 12: protected void DetailsView1_ItemUpdated(o
Line 13: {
Line 14: string problemID = (string)e.Values["ProblemI
Line 15: string userName = (string)e.Values["UserName
Line 16: string userEmail = (string)e.Values["UserEmai
Sorry about the delay; just got back in front of a computer.
The Values property doesn't exist in the ItemInserted event. You need to create properties, set them in the ItemInsertING event (using the e.NewValues() property -- which is a Dictionary), and then reference those properties in the ItemInsertED event.
The Values property doesn't exist in the ItemInserted event. You need to create properties, set them in the ItemInsertING event (using the e.NewValues() property -- which is a Dictionary), and then reference those properties in the ItemInsertED event.
// You'll need properties to hold the values that you're inserting into the database
// You could also do this in ViewState or Session, but why when this is much easier?
// Here are a few properties to get you started; I'm using the v3.5 syntax for brevity
private string ProblemID { get; set; }
private string UserName { get; set; }
private string UserEmail { get; set; }
...
// and so on
protected void DetailsView1_ItemUpdating(Object sender, DetailsViewUpdateEventArgs e)
{
// Iterate though the values entered by the user and HTML encode
// the values. This helps prevent malicious values from being stored in the data source.
for(int 1 == 0; i < e.Values.Count; i++)
{
if(e.NewValues(i) != null)
{
// you need to develop some logic to figure out which value to set! Something like...
switch(e.Keys(i).ToString())
{
case "ProblemID":
this.ProblemID = Server.HtmlEncode(e.NewValues(i).ToString());
break;
case "UserName":
this.UserName = Server.HtmlEncode(e.NewValues(i).ToString());
break;
case "UserEmail":
this.UserEmail = Server.HtmlEncode(e.NewValues(i).ToString());
break;
// you'll set the rest of the properties the same way
}
}
}
}
protected void DetailsView1_ItemUpdating(Object sender, DetailsViewUpdatedEventArgs e)
{
// Now access the properties you just set in the ItemUpdating method.
// This is where you old code goes, adjusted accordinglingy; for example
// I'm guessing what some of your properties may be named.
string problemID = this.ProblemID;
string userName = this.UserName;
string userEmail = this.UserEmail;
}
I thought about this a little bit more, and you actually probably could pass the whole e.Values() property forward using a single property in your class. If you want to try that then you'll declare just one property and iterate over that one like you tried to do before.
// declare the property
private Dictionary<string, string> MyValues { get; set; }
protected void DetailsView1_ItemUpdating(Object sender, DetailsViewUpdateEventArgs e)
{
// Iterate though the values entered by the user and HTML encode
// the values. This helps prevent malicious values from being stored in the data source.
for(int 1 == 0; i < e.Keys.Count; i++)
{
if(e.Keys(i) != null && e.NewValues(i) != null)
MyValues.Add(e.Keys(i).ToString(), e.NewValues(i).ToString());
}
}
ASKER
azarc3,
In the detail view I am editing only two fields(solution and knowledge base notes) and sending those values as email with other values which are read only = true
In my DetailView1_itemInsert - I am trying to pull all the values which are already there in my detail view by using
string problemID = (string)e.Values["ProblemI D"];
string userName = (string)e.Values["UserName "];
and then I am displaying those values in the email which I was trying to send to an user.
I tried the above code which you have mentioned, its throwing me an compliation error again
CS0501: 'ASP.teammembers_tmeditpro blems4_asp x.MyValues .get' must declare a body because it is not marked abstract or extern
// declare the property
private Dictionary<string, string> MyValues { get; set; }
protected void DetailsView1_ItemUpdating( Object sender, DetailsViewUpdateEventArgs e)
{
....}
In the detail view I am editing only two fields(solution and knowledge base notes) and sending those values as email with other values which are read only = true
In my DetailView1_itemInsert - I am trying to pull all the values which are already there in my detail view by using
string problemID = (string)e.Values["ProblemI
string userName = (string)e.Values["UserName
and then I am displaying those values in the email which I was trying to send to an user.
I tried the above code which you have mentioned, its throwing me an compliation error again
CS0501: 'ASP.teammembers_tmeditpro
// declare the property
private Dictionary<string, string> MyValues { get; set; }
protected void DetailsView1_ItemUpdating(
{
....}
ASKER
azarc3,
is there any other way i can approach and get the output, besides what i tried?
is there any other way i can approach and get the output, besides what i tried?
Most definitely. However, you've already got your structure in place and believe me or not it's almost "right". Give me a minute to check the compiliation error and I'll be right back.
Just realized that you're using ASP.NET 2.0 and not ASP.NET 3.5... had to massage this just a bit to fit your existing code... try the code below. Regardless of the result, just remember that we're almost there.
Sorry about that previous example; I was hacking that at my wife's machine in Notepad and didn't actually build it. :(
Sorry about that previous example; I was hacking that at my wife's machine in Notepad and didn't actually build it. :(
private Dictionary<string, string> _myValues;
// declare the property
private Dictionary<string, string> MyValues
{
get { return _myValues; }
set { _myValues = value; }
}
protected void DetailsView1_ItemUpdating(Object sender, DetailsViewUpdateEventArgs e)
{
// Iterate though the values entered by the user and HTML encode
// the values. This helps prevent malicious values from being stored in the data source.
for (int i = 0; i < e.Keys.Count; i++)
{
if (e.Keys[i] != null && e.NewValues[i] != null)
MyValues.Add(e.Keys[i].ToString(), e.NewValues[i].ToString());
}
}
ASKER
Thanks a lot for helping me with this problem :) ....
I am still getting compilation error
CS1518: Expected class, delegate, enum, interface, or struct
Line 29: protected void DetailsView1_ItemUpdated(o bject sender, DetailsViewUpdatedEventArg s e)
This is what i have done so far
private Dictionary<string, string> MyValues
{
get { return _myValues; }
set { _myValues = value; }
}
protected void DetailsView1_ItemUpdating( Object sender, DetailsViewUpdateEventArgs e)
{
for (int i = 0; i < e.Keys.Count; i++)
{
if (e.Keys[i] != null && e.NewValues[i] != null)
MyValues.Add(e.Keys[i].ToS tring(), e.NewValues[i].ToString()) ;
}
}
}
protected void DetailsView1_ItemUpdated(o bject sender, DetailsViewUpdatedEventArg s e)
{
string problemID = (string)e.Values["ProblemI D"];
string userName = (string)e.Values["UserName "];
string userEmail = (string)e.Values["UserEmai l"];
string userLocation = (string)e.Values["UserLoca tion"];
string userPhone = (string)e.Values["UserPhon e"];
string ocd = (string)e.Values["ocd"];
string DepartmentName = (string)e.Values["Departme ntName"];
string UserNH = (string)e.Values["UserNH"] ;
string UserSSN = (string)e.Values["UserSSN" ];
string IsRepresentativeInvolved = (string)e.Values["IsRepres entativeIn volved"];
string RepresentativeSSN = (string)e.Values["Represen tativeSSN" ];
string RepresentativeZipCode = (string)e.Values["Represen tativeZipC ode"];
string OrganizationName = (string)e.Values["Organiza tionName"] ;
string ClaimantName = (string)e.Values["Claimant Name"];
string IsProblemQuestion = (string)e.Values["IsProble mQuestion" ];
string IsComment = (string)e.Values["IsCommen t"];
string ProblemTitle = (string)e.Values["ProblemT itle"];
string ProblemDescription = (string)e.Values["ProblemD escription "];
string Attachment = (string)e.Values["Attachme nt"];
string TeamMemberName = (string)e.Values["TeamMemb erName"];
string solution = (string)e.Values["solution "];
string KnowledgeBaseNotes = (string)e.Values["Knowledg eBaseNotes "];
I am still getting compilation error
CS1518: Expected class, delegate, enum, interface, or struct
Line 29: protected void DetailsView1_ItemUpdated(o
This is what i have done so far
private Dictionary<string, string> MyValues
{
get { return _myValues; }
set { _myValues = value; }
}
protected void DetailsView1_ItemUpdating(
{
for (int i = 0; i < e.Keys.Count; i++)
{
if (e.Keys[i] != null && e.NewValues[i] != null)
MyValues.Add(e.Keys[i].ToS
}
}
}
protected void DetailsView1_ItemUpdated(o
{
string problemID = (string)e.Values["ProblemI
string userName = (string)e.Values["UserName
string userEmail = (string)e.Values["UserEmai
string userLocation = (string)e.Values["UserLoca
string userPhone = (string)e.Values["UserPhon
string ocd = (string)e.Values["ocd"];
string DepartmentName = (string)e.Values["Departme
string UserNH = (string)e.Values["UserNH"]
string UserSSN = (string)e.Values["UserSSN"
string IsRepresentativeInvolved = (string)e.Values["IsRepres
string RepresentativeSSN = (string)e.Values["Represen
string RepresentativeZipCode = (string)e.Values["Represen
string OrganizationName = (string)e.Values["Organiza
string ClaimantName = (string)e.Values["Claimant
string IsProblemQuestion = (string)e.Values["IsProble
string IsComment = (string)e.Values["IsCommen
string ProblemTitle = (string)e.Values["ProblemT
string ProblemDescription = (string)e.Values["ProblemD
string Attachment = (string)e.Values["Attachme
string TeamMemberName = (string)e.Values["TeamMemb
string solution = (string)e.Values["solution
string KnowledgeBaseNotes = (string)e.Values["Knowledg
ASKER
I have also imported
<%@ Import Namespace="System.Collecti ons.Generi c" %>
<%@ Import Namespace="System.Collecti
Ok. I went back and setup a test project that is ASP.NET v2.0 and came up with the following.
1. Get rid of the _myValues declaration.
2. Get rid of the MyValues property.
3. Comment out your your DetailsView1_ItemUpdated() method; I think we'll be getting rid of this later.
4. Use the following snippet to set the variable values in your DetailsView1_ItemUpdated() method.
Let me know what happens.
1. Get rid of the _myValues declaration.
2. Get rid of the MyValues property.
3. Comment out your your DetailsView1_ItemUpdated()
4. Use the following snippet to set the variable values in your DetailsView1_ItemUpdated()
Let me know what happens.
string problemID = e.Keys["ProblemID"].ToString();
string userName = e.Keys["UserName"].ToString();
string userEmail = e.Keys["UserEmail"].ToString();
string userLocation = e.Keys["UserLocation"].ToString();
string userPhone = e.Keys["UserPhone"].ToString();
string ocd = e.Keys["ocd"].ToString();
string DepartmentName = e.Keys["DepartmentName"].ToString();
string UserNH = e.Keys["UserNH"].ToString();
string UserSSN = e.Keys["UserSSN"].ToString();
string IsRepresentativeInvolved = e.Keys["IsRepresentativeInvolved"].ToString();
string RepresentativeSSN = e.Keys["RepresentativeSSN"].ToString();
string RepresentativeZipCode = e.Keys["RepresentativeZipCode"].ToString();
string OrganizationName = e.Keys["OrganizationName"].ToString();
string ClaimantName = e.Keys["ClaimantName"].ToString();
string IsProblemQuestion = e.Keys["IsProblemQuestion"].ToString();
string IsComment = e.Keys["IsComment"].ToString();
string ProblemTitle = e.Keys["ProblemTitle"].ToString();
string ProblemDescription = e.Keys["ProblemDescription"].ToString();
string Attachment = e.Keys["Attachment"].ToString();
string TeamMemberName = e.Keys["TeamMemberName"].ToString();
string solution = e.Keys["solution"].ToString();
string KnowledgeBaseNotes = e.Keys["KnowledgeBaseNotes"].ToString();
ASKER
azarc
I tried the above code, first I didnt see any error, but when I tried to clicking on the update button after editing the problem with Solution and knowledge base notes in it.
Got this compilation error message
System.NullReferenceExcept ion: Object reference not set to an instance of an object.
Line 16: string problemID = e.Keys["ProblemID"].ToStri ng();
I tried the above code, first I didnt see any error, but when I tried to clicking on the update button after editing the problem with Solution and knowledge base notes in it.
Got this compilation error message
System.NullReferenceExcept
Line 16: string problemID = e.Keys["ProblemID"].ToStri
Yeah; you're going to have to check each one of those to see if there's an actual key/value pair there... I meant to mention that but forgot. So, for example, in the case of ProblemID...
if(e.Keys["ProblemID"] != null)
{
string problemID = e.Keys["ProblemID"].ToStri ng();
}
You'll need to do that for each one.
if(e.Keys["ProblemID"] != null)
{
string problemID = e.Keys["ProblemID"].ToStri
}
You'll need to do that for each one.
ASKER
Tried incorporate the code...got the error message
CS0136: A local variable named 'problemID' cannot be declared in this scope because it would give a different meaning to 'problemID', which is already used in a 'parent or current' scope to denote something else
Line 41: string problemID = e.Keys["ProblemID"].ToStri ng();
CS0136: A local variable named 'problemID' cannot be declared in this scope because it would give a different meaning to 'problemID', which is already used in a 'parent or current' scope to denote something else
Line 41: string problemID = e.Keys["ProblemID"].ToStri
Here's your options with that error...
1. Do a find on your page for problemID and make sure "Match case" is checked. That will tell you where the other one(s) is/are and you can decide from there what you want or need to do.
2. The simpler, however, is to remove the declaration cast so your simple setting the value of problemID...
INSTEAD OF THIS:
string problemID = e.Keys["ProblemID"].ToStri ng();
DO THIS:
problemID = e.Keys["ProblemID"].ToStri ng();
The only problem with this approach is that if you need problemID somewhere else and its previous value is necessary then you could be setting yourself up for failure.
1. Do a find on your page for problemID and make sure "Match case" is checked. That will tell you where the other one(s) is/are and you can decide from there what you want or need to do.
2. The simpler, however, is to remove the declaration cast so your simple setting the value of problemID...
INSTEAD OF THIS:
string problemID = e.Keys["ProblemID"].ToStri
DO THIS:
problemID = e.Keys["ProblemID"].ToStri
The only problem with this approach is that if you need problemID somewhere else and its previous value is necessary then you could be setting yourself up for failure.
ASKER
azarc,
This is what i am trying to achieve in this page:
I was trying to edit a problem (by entering solution and knowledge base notes). After I click on the Update button, Status of the Problem is Closed.
I was trying to send email to the user with all the data ( the information which is there already in Detail view (read only view) and the Solution and knowledge Base notes too). I cannot send the email to the user without Solution and Knowledge Base notes. Which I am trying to achieve. But I dont know how to do that. I thought after update the ticket it will send email. But it doesnt look like that. After clicking on the Update button, Solution and Knowledge Base notes are getting update and the status is changing to closed.
But I am still seeing the error message and no email
System.NullReferenceExcept ion: Object reference not set to an instance of an object.
Line 17: UserName = e.Keys["UserName"].ToStrin g();
This is so much easier to do in core ASP than in .net ...:(
This is what i am trying to achieve in this page:
I was trying to edit a problem (by entering solution and knowledge base notes). After I click on the Update button, Status of the Problem is Closed.
I was trying to send email to the user with all the data ( the information which is there already in Detail view (read only view) and the Solution and knowledge Base notes too). I cannot send the email to the user without Solution and Knowledge Base notes. Which I am trying to achieve. But I dont know how to do that. I thought after update the ticket it will send email. But it doesnt look like that. After clicking on the Update button, Solution and Knowledge Base notes are getting update and the status is changing to closed.
But I am still seeing the error message and no email
System.NullReferenceExcept
Line 17: UserName = e.Keys["UserName"].ToStrin
This is so much easier to do in core ASP than in .net ...:(
Did you put the conditional check with each variable, or only on the ProblemID? You're going to have to do it for each one...
The problem is that the values you are looking for are inside of an object, and they aren't guaranteed to be set before you try and evaluate a method on that value (the ToString()). You can't perform an operation on something that doesn't exist, which is what's happening when there's no value for a particular item in the Details View. That's why you have to check each one before you attempt to evaluate it. This is part of why I was saying, "You're almost there" before... there are other ways, but you'd basically have to start from scratch.
So, let's continue down this road and make sure the things we KNOW we have to do aren't the culprit. Use the code below and let's see what the next error is. Just a little more patience; you're getting closer. :)
The problem is that the values you are looking for are inside of an object, and they aren't guaranteed to be set before you try and evaluate a method on that value (the ToString()). You can't perform an operation on something that doesn't exist, which is what's happening when there's no value for a particular item in the Details View. That's why you have to check each one before you attempt to evaluate it. This is part of why I was saying, "You're almost there" before... there are other ways, but you'd basically have to start from scratch.
So, let's continue down this road and make sure the things we KNOW we have to do aren't the culprit. Use the code below and let's see what the next error is. Just a little more patience; you're getting closer. :)
if (e.Keys["ProblemID"] != null)
{
string problemID = e.Keys["ProblemID"].ToString();
}
if (e.Keys["UserName"] != null)
{
string userName = e.Keys["UserName"].ToString();
}
if (e.Keys["UserEmail"] != null)
{
string userEmail = e.Keys["UserEmail"].ToString();
}
if (e.Keys["UserLocation"] != null)
{
string userLocation = e.Keys["UserLocation"].ToString();
}
if (e.Keys["UserPhone"] != null)
{
string userPhone = e.Keys["UserPhone"].ToString();
}
if (e.Keys["ocd"] != null)
{
string ocd = e.Keys["ocd"].ToString();
}
if (e.Keys["DepartmentName"] != null)
{
string DepartmentName = e.Keys["DepartmentName"].ToString();
}
if (e.Keys["UserNH"] != null)
{
string UserNH = e.Keys["UserNH"].ToString();
}
if (e.Keys["UserSSN"] != null)
{
string UserSSN = e.Keys["UserSSN"].ToString();
}
if (e.Keys["IsRepresentativeInvolved"] != null)
{
string IsRepresentativeInvolved = e.Keys["IsRepresentativeInvolved"].ToString();
}
if (e.Keys["RepresentativeSSN"] != null)
{
string RepresentativeSSN = e.Keys["RepresentativeSSN"].ToString();
}
if (e.Keys["RepresentativeZipCode"] != null)
{
string RepresentativeZipCode = e.Keys["RepresentativeZipCode"].ToString();
}
if (e.Keys["OrganizationName"] != null)
{
string OrganizationName = e.Keys["OrganizationName"].ToString();
}
if (e.Keys["ClaimantName"] != null)
{
string ClaimantName = e.Keys["ClaimantName"].ToString();
}
if (e.Keys["IsProblemQuestion"] != null)
{
string IsProblemQuestion = e.Keys["IsProblemQuestion"].ToString();
}
if (e.Keys["IsComment"] != null)
{
string IsComment = e.Keys["IsComment"].ToString();
}
if (e.Keys["ProblemTitle"] != null)
{
string ProblemTitle = e.Keys["ProblemTitle"].ToString();
}
if (e.Keys["ProblemDescription"] != null)
{
string ProblemDescription = e.Keys["ProblemDescription"].ToString();
}
if (e.Keys["Attachment"] != null)
{
string Attachment = e.Keys["Attachment"].ToString();
}
if (e.Keys["TeamMemberName"] != null)
{
string TeamMemberName = e.Keys["TeamMemberName"].ToString();
}
if (e.Keys["solution"] != null)
{
string solution = e.Keys["solution"].ToString();
}
if (e.Keys["KnowledgeBaseNotes"] != null)
{
string KnowledgeBaseNotes = e.Keys["KnowledgeBaseNotes"].ToString();
}
If necessary, don't forget to remove the leading "string" on string {variablename} = e.Keys["whatever"].ToStrin g().
ASKER
azarc,
I tried exactly same thing as you have mentioned above, I am checking it for each and every field and even i removed the string too
Here is the error message:
CS0103: The name 'ProblemStatusId' does not exist in the current context
Line 16: ProblemStatusId= e.Keys["ProblemStatusId"]. ToString() ;
protected void DetailsView1_ItemUpdated(o bject sender, DetailsViewUpdatedEventArg s e)
{
ProblemStatusId= e.Keys["ProblemStatusId"]. ToString() ;
UserName = e.Keys["UserName"].ToStrin g();
UserEmail = e.Keys["UserEmail"].ToStri ng();
UserLocation = e.Keys["UserLocation"].ToS tring();
UserPhone = e.Keys["UserPhone"].ToStri ng();
ocd = e.Keys["ocd"].ToString();
DepartmentName = e.Keys["DepartmentName"].T oString();
UserNH = e.Keys["UserNH"].ToString( );
UserSSN = e.Keys["UserSSN"].ToString ();
IsRepresentativeInvolved = e.Keys["IsRepresentativeIn volved"].T oString();
RepresentativeSSN = e.Keys["RepresentativeSSN" ].ToString ();
RepresentativeZipCode = e.Keys["RepresentativeZipC ode"].ToSt ring();
OrganizationName = e.Keys["OrganizationName"] .ToString( );
ClaimantName = e.Keys["ClaimantName"].ToS tring();
IsProblemQuestion = e.Keys["IsProblemQuestion" ].ToString ();
IsComment = e.Keys["IsComment"].ToStri ng();
ProblemTitle = e.Keys["ProblemTitle"].ToS tring();
ProblemDescription = e.Keys["ProblemDescription "].ToStrin g();
Attachment = e.Keys["Attachment"].ToStr ing();
TeamMemberName = e.Keys["TeamMemberName"].T oString();
solution = e.Keys["solution"].ToStrin g();
KnowledgeBaseNotes = e.Keys["KnowledgeBaseNotes "].ToStrin g();
if(e.Keys["ProblemStatusId "] != null)
{
string ProblemStatusId = e.Keys["ProblemStatusId"]. ToString() ;
}
if(e.Keys["UserName"] != null)
{
string UserName = e.Keys["UserName"].ToStrin g();
}
if(e.Keys["UserEmail"] != null)
{
string UserEmail = e.Keys["UserEmail"].ToStri ng();
}
if(e.Keys["UserLocation"] != null)
{
string UserLocation = e.Keys["UserLocation"].ToS tring();
}
if(e.Keys["UserPhone"] != null)
{
string UserPhone = e.Keys["UserPhone"].ToStri ng();
}
if(e.Keys["ocd"] != null)
{
string ocd = e.Keys["ocd"].ToString();
}
if(e.Keys["DepartmentName" ] != null)
{
string DepartmentName = e.Keys["DepartmentName"].T oString();
}
if(e.Keys["UserNH"] != null)
{
string UserNH = e.Keys["UserNH"].ToString( );
}
if(e.Keys["UserSSN"] != null)
{
string UserSSN = e.Keys["UserSSN"].ToString ();
}
if(e.Keys["IsRepresentativ eInvolved" ] != null)
{
string IsRepresentativeInvolved = e.Keys["IsRepresentativeIn volved"].T oString();
}
if(e.Keys["RepresentativeS SN"] != null)
{
string RepresentativeSSN = e.Keys["RepresentativeSSN" ].ToString ();
}
if(e.Keys["RepresentativeZ ipCode"] != null)
{
string RepresentativeZipCode = e.Keys["RepresentativeZipC ode"].ToSt ring();
}
if(e.Keys["OrganizationNam e"] != null)
{
string OrganizationName = e.Keys["OrganizationName"] .ToString( );
}
if(e.Keys["ClaimantName"] != null)
{
string ClaimantName = e.Keys["ClaimantName"].ToS tring();
}
if(e.Keys["IsProblemQuesti on"] != null)
{
string IsProblemQuestion = e.Keys["IsProblemQuestion" ].ToString ();
}
if(e.Keys["IsComment"] != null)
{
string IsComment = e.Keys["IsComment"].ToStri ng();
}
if(e.Keys["ProblemTitle"] != null)
{
string ProblemTitle = e.Keys["ProblemTitle"].ToS tring();
}
if(e.Keys["ProblemDescript ion"] != null)
{
string ProblemDescription = e.Keys["ProblemDescription "].ToStrin g();
}
if(e.Keys["Attachment"] != null)
{
string Attachment = e.Keys["Attachment"].ToStr ing();
}
if(e.Keys["TeamMemberName" ] != null)
{
string TeamMemberName = e.Keys["TeamMemberName"].T oString();
}
if(e.Keys["solution"] != null)
{
string solution = e.Keys["solution"].ToStrin g();
}
if(e.Keys["KnowledgeBaseNo tes"] != null)
{
string KnowledgeBaseNotes = e.Keys["KnowledgeBaseNotes "].ToStrin g();
}
I tried exactly same thing as you have mentioned above, I am checking it for each and every field and even i removed the string too
Here is the error message:
CS0103: The name 'ProblemStatusId' does not exist in the current context
Line 16: ProblemStatusId= e.Keys["ProblemStatusId"].
protected void DetailsView1_ItemUpdated(o
{
ProblemStatusId= e.Keys["ProblemStatusId"].
UserName = e.Keys["UserName"].ToStrin
UserEmail = e.Keys["UserEmail"].ToStri
UserLocation = e.Keys["UserLocation"].ToS
UserPhone = e.Keys["UserPhone"].ToStri
ocd = e.Keys["ocd"].ToString();
DepartmentName = e.Keys["DepartmentName"].T
UserNH = e.Keys["UserNH"].ToString(
UserSSN = e.Keys["UserSSN"].ToString
IsRepresentativeInvolved = e.Keys["IsRepresentativeIn
RepresentativeSSN = e.Keys["RepresentativeSSN"
RepresentativeZipCode = e.Keys["RepresentativeZipC
OrganizationName = e.Keys["OrganizationName"]
ClaimantName = e.Keys["ClaimantName"].ToS
IsProblemQuestion = e.Keys["IsProblemQuestion"
IsComment = e.Keys["IsComment"].ToStri
ProblemTitle = e.Keys["ProblemTitle"].ToS
ProblemDescription = e.Keys["ProblemDescription
Attachment = e.Keys["Attachment"].ToStr
TeamMemberName = e.Keys["TeamMemberName"].T
solution = e.Keys["solution"].ToStrin
KnowledgeBaseNotes = e.Keys["KnowledgeBaseNotes
if(e.Keys["ProblemStatusId
{
string ProblemStatusId = e.Keys["ProblemStatusId"].
}
if(e.Keys["UserName"] != null)
{
string UserName = e.Keys["UserName"].ToStrin
}
if(e.Keys["UserEmail"] != null)
{
string UserEmail = e.Keys["UserEmail"].ToStri
}
if(e.Keys["UserLocation"] != null)
{
string UserLocation = e.Keys["UserLocation"].ToS
}
if(e.Keys["UserPhone"] != null)
{
string UserPhone = e.Keys["UserPhone"].ToStri
}
if(e.Keys["ocd"] != null)
{
string ocd = e.Keys["ocd"].ToString();
}
if(e.Keys["DepartmentName"
{
string DepartmentName = e.Keys["DepartmentName"].T
}
if(e.Keys["UserNH"] != null)
{
string UserNH = e.Keys["UserNH"].ToString(
}
if(e.Keys["UserSSN"] != null)
{
string UserSSN = e.Keys["UserSSN"].ToString
}
if(e.Keys["IsRepresentativ
{
string IsRepresentativeInvolved = e.Keys["IsRepresentativeIn
}
if(e.Keys["RepresentativeS
{
string RepresentativeSSN = e.Keys["RepresentativeSSN"
}
if(e.Keys["RepresentativeZ
{
string RepresentativeZipCode = e.Keys["RepresentativeZipC
}
if(e.Keys["OrganizationNam
{
string OrganizationName = e.Keys["OrganizationName"]
}
if(e.Keys["ClaimantName"] != null)
{
string ClaimantName = e.Keys["ClaimantName"].ToS
}
if(e.Keys["IsProblemQuesti
{
string IsProblemQuestion = e.Keys["IsProblemQuestion"
}
if(e.Keys["IsComment"] != null)
{
string IsComment = e.Keys["IsComment"].ToStri
}
if(e.Keys["ProblemTitle"] != null)
{
string ProblemTitle = e.Keys["ProblemTitle"].ToS
}
if(e.Keys["ProblemDescript
{
string ProblemDescription = e.Keys["ProblemDescription
}
if(e.Keys["Attachment"] != null)
{
string Attachment = e.Keys["Attachment"].ToStr
}
if(e.Keys["TeamMemberName"
{
string TeamMemberName = e.Keys["TeamMemberName"].T
}
if(e.Keys["solution"] != null)
{
string solution = e.Keys["solution"].ToStrin
}
if(e.Keys["KnowledgeBaseNo
{
string KnowledgeBaseNotes = e.Keys["KnowledgeBaseNotes
}
It appears you're declaring the same variables twice, and you're not evaluating for a null reference the first time through.
Delete or comment out the following lines at the top of the DetailsView1_ItemUpdated() method...
Delete or comment out the following lines at the top of the DetailsView1_ItemUpdated()
ProblemStatusId= e.Keys["ProblemStatusId"].ToString();
UserName = e.Keys["UserName"].ToString();
UserEmail = e.Keys["UserEmail"].ToString();
UserLocation = e.Keys["UserLocation"].ToString();
UserPhone = e.Keys["UserPhone"].ToString();
ocd = e.Keys["ocd"].ToString();
DepartmentName = e.Keys["DepartmentName"].ToString();
UserNH = e.Keys["UserNH"].ToString();
UserSSN = e.Keys["UserSSN"].ToString();
IsRepresentativeInvolved = e.Keys["IsRepresentativeInvolved"].ToString();
RepresentativeSSN = e.Keys["RepresentativeSSN"].ToString();
RepresentativeZipCode = e.Keys["RepresentativeZipCode"].ToString();
OrganizationName = e.Keys["OrganizationName"].ToString();
ClaimantName = e.Keys["ClaimantName"].ToString();
IsProblemQuestion = e.Keys["IsProblemQuestion"].ToString();
IsComment = e.Keys["IsComment"].ToString();
ProblemTitle = e.Keys["ProblemTitle"].ToString();
ProblemDescription = e.Keys["ProblemDescription"].ToString();
Attachment = e.Keys["Attachment"].ToString();
TeamMemberName = e.Keys["TeamMemberName"].ToString();
solution = e.Keys["solution"].ToString();
KnowledgeBaseNotes = e.Keys["KnowledgeBaseNotes"].ToString();
my bad; just realized why you're doing that... do this instead at the top of the DetailsView1_ItemUpdated() method...
string ProblemStatusId;
string UserName;
string UserEmail;
string UserLocation;
string UserPhone;
string ocd;
string DepartmentName;
string UserNH;
string UserSSN;
string IsRepresentativeInvolved;
string RepresentativeSSN;
string RepresentativeZipCode;
string OrganizationName;
string ClaimantName;
string IsProblemQuestion;
string IsComment;
string ProblemTitle;
string ProblemDescription;
string Attachment;
string TeamMemberName;
string solution;
string KnowledgeBaseNotes;
Otherwise you won't be able to access those later on in the method.
ASKER
This is what i have done , Still getting error message
CS0135: 'UserEmail' conflicts with the declaration 'ASP.teammembers_tmeditpro blems7_asp x.UserEmai l'
Line 132:message.To.Add(new MailAddress(UserEmail, UserName));
<script runat="server">
string ProblemStatusId;
string UserName;
string UserEmail;
string UserLocation;
string UserPhone;
string ocd;
string DepartmentName;
string UserNH;
string UserSSN;
string IsRepresentativeInvolved;
string RepresentativeSSN;
string RepresentativeZipCode;
string OrganizationName;
string ClaimantName;
string IsProblemQuestion;
string IsComment;
string ProblemTitle;
string ProblemDescription;
string Attachment;
string TeamMemberName;
string solution;
string KnowledgeBaseNotes;
protected void DetailsView1_ItemUpdated(o bject sender, DetailsViewUpdatedEventArg s e)
{
if(e.Keys["ProblemStatusId "] != null)
{
string ProblemStatusId = e.Keys["ProblemStatusId"]. ToString() ;
}
if(e.Keys["UserName"] != null)
{
string UserName = e.Keys["UserName"].ToStrin g();
}
if(e.Keys["UserEmail"] != null)
{
string UserEmail = e.Keys["UserEmail"].ToStri ng();
}
if(e.Keys["UserLocation"] != null)
{
string UserLocation = e.Keys["UserLocation"].ToS tring();
}
if(e.Keys["UserPhone"] != null)
{
string UserPhone = e.Keys["UserPhone"].ToStri ng();
}
if(e.Keys["ocd"] != null)
{
string ocd = e.Keys["ocd"].ToString();
}
if(e.Keys["DepartmentName" ] != null)
{
string DepartmentName = e.Keys["DepartmentName"].T oString();
}
if(e.Keys["UserNH"] != null)
{
string UserNH = e.Keys["UserNH"].ToString( );
}
if(e.Keys["UserSSN"] != null)
{
string UserSSN = e.Keys["UserSSN"].ToString ();
}
if(e.Keys["IsRepresentativ eInvolved" ] != null)
{
string IsRepresentativeInvolved = e.Keys["IsRepresentativeIn volved"].T oString();
}
if(e.Keys["RepresentativeS SN"] != null)
{
string RepresentativeSSN = e.Keys["RepresentativeSSN" ].ToString ();
}
if(e.Keys["RepresentativeZ ipCode"] != null)
{
string RepresentativeZipCode = e.Keys["RepresentativeZipC ode"].ToSt ring();
}
if(e.Keys["OrganizationNam e"] != null)
{
string OrganizationName = e.Keys["OrganizationName"] .ToString( );
}
if(e.Keys["ClaimantName"] != null)
{
string ClaimantName = e.Keys["ClaimantName"].ToS tring();
}
if(e.Keys["IsProblemQuesti on"] != null)
{
string IsProblemQuestion = e.Keys["IsProblemQuestion" ].ToString ();
}
if(e.Keys["IsComment"] != null)
{
string IsComment = e.Keys["IsComment"].ToStri ng();
}
if(e.Keys["ProblemTitle"] != null)
{
string ProblemTitle = e.Keys["ProblemTitle"].ToS tring();
}
if(e.Keys["ProblemDescript ion"] != null)
{
string ProblemDescription = e.Keys["ProblemDescription "].ToStrin g();
}
if(e.Keys["Attachment"] != null)
{
string Attachment = e.Keys["Attachment"].ToStr ing();
}
if(e.Keys["TeamMemberName" ] != null)
{
string TeamMemberName = e.Keys["TeamMemberName"].T oString();
}
if(e.Keys["solution"] != null)
{
string solution = e.Keys["solution"].ToStrin g();
}
if(e.Keys["KnowledgeBaseNo tes"] != null)
{
string KnowledgeBaseNotes = e.Keys["KnowledgeBaseNotes "].ToStrin g();
}
System.Net.Mail.MailMessag e message = new System.Net.Mail.MailMessag e();
message.From = new MailAddress("shruthi.andem @ssa.gov", "System E-mail");
message.To.Add(new MailAddress(UserEmail, UserName));
message.Subject = "Problem submission";
message.Body =
"Name: " + UserName + "\n" +
"Email: " + UserEmail + "\n" +
"Location: " + UserLocation + "\n" +
"Phone: " + UserPhone + "\n" +
"DOC: " + ocd + "\n" +
"ProblemTitle: " + ProblemTitle + "\n" +
"solution: " + solution + "\n" +
"KnowledgeBaseNotes: " + KnowledgeBaseNotes + "\n" +
"ProblemStatusId: " + ProblemStatusId;
SmtpClient smtp = new SmtpClient("chinet.ch.as.s sa.gov", 25);
smtp.EnableSsl = false;
//smtp.Credentials = new NetworkCredential("","");
smtp.Send(message);
}
CS0135: 'UserEmail' conflicts with the declaration 'ASP.teammembers_tmeditpro
Line 132:message.To.Add(new MailAddress(UserEmail, UserName));
<script runat="server">
string ProblemStatusId;
string UserName;
string UserEmail;
string UserLocation;
string UserPhone;
string ocd;
string DepartmentName;
string UserNH;
string UserSSN;
string IsRepresentativeInvolved;
string RepresentativeSSN;
string RepresentativeZipCode;
string OrganizationName;
string ClaimantName;
string IsProblemQuestion;
string IsComment;
string ProblemTitle;
string ProblemDescription;
string Attachment;
string TeamMemberName;
string solution;
string KnowledgeBaseNotes;
protected void DetailsView1_ItemUpdated(o
{
if(e.Keys["ProblemStatusId
{
string ProblemStatusId = e.Keys["ProblemStatusId"].
}
if(e.Keys["UserName"] != null)
{
string UserName = e.Keys["UserName"].ToStrin
}
if(e.Keys["UserEmail"] != null)
{
string UserEmail = e.Keys["UserEmail"].ToStri
}
if(e.Keys["UserLocation"] != null)
{
string UserLocation = e.Keys["UserLocation"].ToS
}
if(e.Keys["UserPhone"] != null)
{
string UserPhone = e.Keys["UserPhone"].ToStri
}
if(e.Keys["ocd"] != null)
{
string ocd = e.Keys["ocd"].ToString();
}
if(e.Keys["DepartmentName"
{
string DepartmentName = e.Keys["DepartmentName"].T
}
if(e.Keys["UserNH"] != null)
{
string UserNH = e.Keys["UserNH"].ToString(
}
if(e.Keys["UserSSN"] != null)
{
string UserSSN = e.Keys["UserSSN"].ToString
}
if(e.Keys["IsRepresentativ
{
string IsRepresentativeInvolved = e.Keys["IsRepresentativeIn
}
if(e.Keys["RepresentativeS
{
string RepresentativeSSN = e.Keys["RepresentativeSSN"
}
if(e.Keys["RepresentativeZ
{
string RepresentativeZipCode = e.Keys["RepresentativeZipC
}
if(e.Keys["OrganizationNam
{
string OrganizationName = e.Keys["OrganizationName"]
}
if(e.Keys["ClaimantName"] != null)
{
string ClaimantName = e.Keys["ClaimantName"].ToS
}
if(e.Keys["IsProblemQuesti
{
string IsProblemQuestion = e.Keys["IsProblemQuestion"
}
if(e.Keys["IsComment"] != null)
{
string IsComment = e.Keys["IsComment"].ToStri
}
if(e.Keys["ProblemTitle"] != null)
{
string ProblemTitle = e.Keys["ProblemTitle"].ToS
}
if(e.Keys["ProblemDescript
{
string ProblemDescription = e.Keys["ProblemDescription
}
if(e.Keys["Attachment"] != null)
{
string Attachment = e.Keys["Attachment"].ToStr
}
if(e.Keys["TeamMemberName"
{
string TeamMemberName = e.Keys["TeamMemberName"].T
}
if(e.Keys["solution"] != null)
{
string solution = e.Keys["solution"].ToStrin
}
if(e.Keys["KnowledgeBaseNo
{
string KnowledgeBaseNotes = e.Keys["KnowledgeBaseNotes
}
System.Net.Mail.MailMessag
message.From = new MailAddress("shruthi.andem
message.To.Add(new MailAddress(UserEmail, UserName));
message.Subject = "Problem submission";
message.Body =
"Name: " + UserName + "\n" +
"Email: " + UserEmail + "\n" +
"Location: " + UserLocation + "\n" +
"Phone: " + UserPhone + "\n" +
"DOC: " + ocd + "\n" +
"ProblemTitle: " + ProblemTitle + "\n" +
"solution: " + solution + "\n" +
"KnowledgeBaseNotes: " + KnowledgeBaseNotes + "\n" +
"ProblemStatusId: " + ProblemStatusId;
SmtpClient smtp = new SmtpClient("chinet.ch.as.s
smtp.EnableSsl = false;
//smtp.Credentials = new NetworkCredential("","");
smtp.Send(message);
}
That's weird. Try using a simple string instead of a variable to see if it is actually the variable causing the problem.
If that works then you may need to rename one of your variables to get rid of the collision that appears to be happening.
Do the following:
If that works then you may need to rename one of your variables to get rid of the collision that appears to be happening.
Do the following:
message.To.Add("someone@somewhere.com");
ASKER
Azarc,
No it didnt work....
CS0135: 'UserName' conflicts with the declaration 'ASP.teammembers_tmeditpro blems7_asp x.UserName '
Line 133: "Name: " + UserName + "\n" +
No it didnt work....
CS0135: 'UserName' conflicts with the declaration 'ASP.teammembers_tmeditpro
Line 133: "Name: " + UserName + "\n" +
Ok, there's a pattern developing here. You may need to slightly change the variables you create and set in this method. The names are conflicting because they're exactly the same as the fields in your DetailsView1.
ASKER
azarc3,
This time it was my bad, I was trying to execute the code at wrong place.
When I tried to execute the code this time again, I am getting this error message:
To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".
<!-- Web.Config Configuration File --> <configuration> <system.web> <customErrors mode="Off"/> </system.web> </configuration>
Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL.
<!-- Web.Config Configuration File --> <configuration> <system.web> <customErrors mode="RemoteOnly" defaultRedirect="mycustomp age.htm"/> </system.web> </configuration>
This time it was my bad, I was trying to execute the code at wrong place.
When I tried to execute the code this time again, I am getting this error message:
To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".
<!-- Web.Config Configuration File --> <configuration> <system.web> <customErrors mode="Off"/> </system.web> </configuration>
Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL.
<!-- Web.Config Configuration File --> <configuration> <system.web> <customErrors mode="RemoteOnly" defaultRedirect="mycustomp
No problem.
In the root level of your application, I assume there is a web.config file. That's the one that should have the <customError mode="Off" /> in it. If you have more than 1 web.config file that is NOT excluded from the application then you need to make sure <customeErrors> is NOT in them.
In the root level of your application, I assume there is a web.config file. That's the one that should have the <customError mode="Off" /> in it. If you have more than 1 web.config file that is NOT excluded from the application then you need to make sure <customeErrors> is NOT in them.
ASKER
Azarc
I added in my web.config file...and removed the error and able to see the email if i hard code my email address and all the other stuff...But if i try to use UserEmail and UserName....then its throwing error
CS0135: 'UserEmail' conflicts with the declaration 'ASP.teammembers_tmeditpro blems7_asp x.UserEmai l'
Line 128:System.Net.Mail.MailMe ssage message = new System.Net.Mail.MailMessag e();
Line 129:message.From = new MailAddress(san@buy.com, "System E-mail");
Line 130:message.To.Add(new MailAddress(UserEmail, UserName));
Line 131:message.Subject = "Problem submission";
Line 132:message.Body =
I added in my web.config file...and removed the error and able to see the email if i hard code my email address and all the other stuff...But if i try to use UserEmail and UserName....then its throwing error
CS0135: 'UserEmail' conflicts with the declaration 'ASP.teammembers_tmeditpro
Line 128:System.Net.Mail.MailMe
Line 129:message.From = new MailAddress(san@buy.com, "System E-mail");
Line 130:message.To.Add(new MailAddress(UserEmail, UserName));
Line 131:message.Subject = "Problem submission";
Line 132:message.Body =
The problem is that you're doing this in an in-line page, rather than using codebehind. You have to change the name of the variable you're creating in the DetailsView1_ItemUpdated() method to something other than UserEmail... call is theUserEmail and change the references to it in the DetailsView1_ItemUpdated() method. That should work. Don't forget where you're actually referencing the field of DetailsView1 it still needs to be UserEmail.
For example this should work:
string theUserEmail;
if(e.Keys["UserEmail"] != null)
{
theUserEmail = e.Keys["UserEmail"].ToStri ng();
}
message.To.Add(new MailAddress(theUserEmail, UserName));
Note that UserName in the line above will probably throw an error too...
For example this should work:
string theUserEmail;
if(e.Keys["UserEmail"] != null)
{
theUserEmail = e.Keys["UserEmail"].ToStri
}
message.To.Add(new MailAddress(theUserEmail, UserName));
Note that UserName in the line above will probably throw an error too...
ASKER
azarc,
I tried that too, I am still getting the same error
CS0135: 'theUserEmail' conflicts with the declaration 'ASP.teammembers_tmeditpro blems7_asp x.theUserE mail'
Line 130:message.To.Add(new MailAddress(theUserEmail, theUserName));
I tried that too, I am still getting the same error
CS0135: 'theUserEmail' conflicts with the declaration 'ASP.teammembers_tmeditpro
Line 130:message.To.Add(new MailAddress(theUserEmail, theUserName));
Then instead of creating and setting a variable, try using the value directly...
Do this:
message.To.Add(new MailAddress(e.Keys["UserEm ail"].ToSt ring(), theUserName));
Do this:
message.To.Add(new MailAddress(e.Keys["UserEm
ASKER
azarc,
Do you want me to delete
if(e.Keys["ProblemStatusId "] != null)
{
string ProblemStatusId = e.Keys["ProblemStatusId"]. ToString() ;
}
if(e.Keys["UserName"] != null)
{
string UserName = e.Keys["UserName"].ToStrin g();
}
........
and add directly into the email which you have mentioned above
message.To.Add(new MailAddress(e.Keys["UserEm ail"].ToSt ring(), theUserName));
Do you want me to delete
if(e.Keys["ProblemStatusId
{
string ProblemStatusId = e.Keys["ProblemStatusId"].
}
if(e.Keys["UserName"] != null)
{
string UserName = e.Keys["UserName"].ToStrin
}
........
and add directly into the email which you have mentioned above
message.To.Add(new MailAddress(e.Keys["UserEm
No, don't delete all those items!
I suggest you comment ONLY those lines related to "UserEmail" and "UserName" and see if that let's you run the page successfully. That would be the following:
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----
/*
if(e.Keys["UserEmail"] != null)
{
string UserEmail = e.Keys["UserEmail"].ToStri ng();
}
*/
/*
if(e.Keys["UserName"] != null)
{
string UserName = e.Keys["UserName"].ToStrin g();
}
*/
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----
Then, when you're creating the message to send, do this:
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----
message.To.Add(new MailAddress(e.Keys["UserEm ail"].ToSt ring(), e.Keys["UserName"].ToStrin g());
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----
See how that works.
I suggest you comment ONLY those lines related to "UserEmail" and "UserName" and see if that let's you run the page successfully. That would be the following:
--------------------------
/*
if(e.Keys["UserEmail"] != null)
{
string UserEmail = e.Keys["UserEmail"].ToStri
}
*/
/*
if(e.Keys["UserName"] != null)
{
string UserName = e.Keys["UserName"].ToStrin
}
*/
--------------------------
Then, when you're creating the message to send, do this:
--------------------------
message.To.Add(new MailAddress(e.Keys["UserEm
--------------------------
See how that works.
ASKER
azarc,
I am still getting error :(
System.NullReferenceExcept ion: Object reference not set to an instance of an object.
Source Error:
Line 133:message.To.Add(new MailAddress(e.Keys["UserEm ail"].ToSt ring(),e.K eys["UserN ame"].ToSt ring()));
I am still getting error :(
System.NullReferenceExcept
Source Error:
Line 133:message.To.Add(new MailAddress(e.Keys["UserEm
Ok, that narrows the problem significantly. It sounds like you're not actually getting values from DetailsView1 for those fields. Please put a breakpoint at line 133 and debug the page... the objective is to find out if those two keys exist and have data when you are in the DetailsView1_ItemUpdated() method.
Let me know what happens.
Let me know what happens.
ASKER
azarc,
here is the error message:
The name 'UserEmail' does not exist in the current context and The name 'UserName' does not exist in the current context.
But if i run without the Detailview1_itemupdated code , i dont see any errors and i see values are displayed in the grid and detail view :(
here is the error message:
The name 'UserEmail' does not exist in the current context and The name 'UserName' does not exist in the current context.
But if i run without the Detailview1_itemupdated code , i dont see any errors and i see values are displayed in the grid and detail view :(
Are those editable fields in DetailsView1?
ASKER
no they are not editable fields they are read only fields
ASKER
only Knowledgebase and solution fields are editable rest all the fields are read only = true
I think that's the problem. Is there a DataKeys property on the DetailsView control? I can't remember. If so we're going to have use it.
ASKER
azarc,
using expression web I created the GUI version of detail view , the datakey propery in the detail view is problemstatusId ;Something like this
http://74.125.47.132/search?q=cache:TzDZh3UWs7sJ:www.asp.net/LEARN/data-access/tutorial-10-vb.aspx+DataKeys+property+on+the+detail+view&cd=1&hl=en&ct=clnk&gl=us
Here is the complete code of the detail view
<asp:DetailsView id="DetailsView1" runat="server" AutoGenerateRows="False" BackColor="LightGoldenrodY ellow" BorderColor="Tan" BorderWidth="1px" CellPadding="2" DataKeyNames="ProblemStatu sId" DataSourceID="SqlDataSourc e3" ForeColor="Black" GridLines="None" Height="50px" Width="100%" AllowPaging="True" OnItemUpdated="DetailsView 1_ItemUpda ted">
<FooterStyle BackColor="Tan" />
<PagerStyle BackColor="PaleGoldenrod" ForeColor="#ACA899" HorizontalAlign="Center" />
<Fields>
<asp:boundfield DataField="ProblemStatusId " HeaderText="ProblemStatusI d" InsertVisible="False" ReadOnly="True" SortExpression="ProblemSta tusId">
</asp:boundfield>
<asp:boundfield DataField="UserName" HeaderText="UserName" ReadOnly="True" SortExpression="UserName">
</asp:boundfield>
<asp:boundfield DataField="UserEmail" HeaderText="UserEmail" ReadOnly="True" SortExpression="UserEmail" >
</asp:boundfield>
<asp:boundfield DataField="UserLocation" HeaderText="UserLocation" ReadOnly="True" SortExpression="UserLocati on">
</asp:boundfield>
<asp:boundfield DataField="UserPhone" HeaderText="UserPhone" ReadOnly="True" SortExpression="UserPhone" >
</asp:boundfield>
<asp:boundfield DataField="ocd" HeaderText="ocd" ReadOnly="True" SortExpression="ocd">
</asp:boundfield>
<asp:boundfield DataField="DepartmentName" HeaderText="DepartmentName " ReadOnly="True" SortExpression="Department Name">
</asp:boundfield>
<asp:boundfield DataField="UserNH" HeaderText="UserNH" ReadOnly="True" SortExpression="UserNH">
</asp:boundfield>
<asp:boundfield DataField="UserSSN" HeaderText="UserSSN" ReadOnly="True" SortExpression="UserSSN">
</asp:boundfield>
<asp:checkboxfield DataField="IsRepresentativ eInvolved" HeaderText="IsRepresentati veInvolved " ReadOnly="True" SortExpression="IsRepresen tativeInvo lved">
</asp:checkboxfield>
<asp:boundfield DataField="RepresentativeS SN" HeaderText="Representative SSN" ReadOnly="True" SortExpression="Representa tiveSSN">
</asp:boundfield>
<asp:boundfield DataField="RepresentativeZ ipCode" HeaderText="Representative ZipCode" ReadOnly="True" SortExpression="Representa tiveZipCod e">
</asp:boundfield>
<asp:boundfield DataField="OrganizationNam e" HeaderText="OrganizationNa me" ReadOnly="True" SortExpression="Organizati onName">
</asp:boundfield>
<asp:boundfield DataField="ClaimantName" HeaderText="ClaimantName" ReadOnly="True" SortExpression="ClaimantNa me">
</asp:boundfield>
<asp:checkboxfield DataField="IsProblemQuesti on" HeaderText="IsProblemQuest ion" ReadOnly="True" SortExpression="IsProblemQ uestion">
</asp:checkboxfield>
<asp:checkboxfield DataField="IsComment" HeaderText="IsComment" ReadOnly="True" SortExpression="IsComment" >
</asp:checkboxfield>
<asp:boundfield DataField="ProblemTitle" HeaderText="ProblemTitle" ReadOnly="True" SortExpression="ProblemTit le">
</asp:boundfield>
<asp:boundfield DataField="ProblemDescript ion" HeaderText="ProblemDescrip tion" ReadOnly="True" SortExpression="ProblemDes cription">
</asp:boundfield>
<asp:boundfield DataField="Attachment" HeaderText="Attachment" ReadOnly="True" SortExpression="Attachment ">
</asp:boundfield>
<asp:boundfield DataField="TeamMemberName" HeaderText="TeamMemberName " ReadOnly="True" SortExpression="TeamMember Name">
</asp:boundfield>
<asp:boundfield DataField="solution" HeaderText="solution" SortExpression="solution">
</asp:boundfield>
<asp:boundfield DataField="KnowledgeBaseNo tes" HeaderText="KnowledgeBaseN otes" SortExpression="KnowledgeB aseNotes">
</asp:boundfield>
<asp:commandfield ShowEditButton="True" ShowInsertButton="True">
</asp:commandfield>
</Fields>
<HeaderStyle BackColor="Tan" Font-Bold="True" />
<EditRowStyle BackColor="PaleGoldenrod" ForeColor="Black" />
<AlternatingRowStyle BackColor="PaleGoldenrod" />
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:HelpDesk Connection String %>" SelectCommand="GetInformat ionForProb lemStatusI dforAdmin" SelectCommandType="StoredP rocedure" UpdateCommand="InsertOrUpd ateAndClos edPSandKB" UpdateCommandType="StoredP rocedure">
<SelectParameters>
<asp:controlparameter ControlID="GridView1" Name="problemStatusId" PropertyName="SelectedValu e" Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:parameter Name="KnowledgeBaseNotes" Type="String" />
<asp:parameter Direction="InputOutput" Name="problem_solution_id" Type="Int32" />
<asp:parameter Name="ProblemStatusID" Type="Int32" />
<asp:parameter Name="Solution" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
using expression web I created the GUI version of detail view , the datakey propery in the detail view is problemstatusId ;Something like this
http://74.125.47.132/search?q=cache:TzDZh3UWs7sJ:www.asp.net/LEARN/data-access/tutorial-10-vb.aspx+DataKeys+property+on+the+detail+view&cd=1&hl=en&ct=clnk&gl=us
Here is the complete code of the detail view
<asp:DetailsView id="DetailsView1" runat="server" AutoGenerateRows="False" BackColor="LightGoldenrodY
<FooterStyle BackColor="Tan" />
<PagerStyle BackColor="PaleGoldenrod" ForeColor="#ACA899" HorizontalAlign="Center" />
<Fields>
<asp:boundfield DataField="ProblemStatusId
</asp:boundfield>
<asp:boundfield DataField="UserName" HeaderText="UserName" ReadOnly="True" SortExpression="UserName">
</asp:boundfield>
<asp:boundfield DataField="UserEmail" HeaderText="UserEmail" ReadOnly="True" SortExpression="UserEmail"
</asp:boundfield>
<asp:boundfield DataField="UserLocation" HeaderText="UserLocation" ReadOnly="True" SortExpression="UserLocati
</asp:boundfield>
<asp:boundfield DataField="UserPhone" HeaderText="UserPhone" ReadOnly="True" SortExpression="UserPhone"
</asp:boundfield>
<asp:boundfield DataField="ocd" HeaderText="ocd" ReadOnly="True" SortExpression="ocd">
</asp:boundfield>
<asp:boundfield DataField="DepartmentName"
</asp:boundfield>
<asp:boundfield DataField="UserNH" HeaderText="UserNH" ReadOnly="True" SortExpression="UserNH">
</asp:boundfield>
<asp:boundfield DataField="UserSSN" HeaderText="UserSSN" ReadOnly="True" SortExpression="UserSSN">
</asp:boundfield>
<asp:checkboxfield DataField="IsRepresentativ
</asp:checkboxfield>
<asp:boundfield DataField="RepresentativeS
</asp:boundfield>
<asp:boundfield DataField="RepresentativeZ
</asp:boundfield>
<asp:boundfield DataField="OrganizationNam
</asp:boundfield>
<asp:boundfield DataField="ClaimantName" HeaderText="ClaimantName" ReadOnly="True" SortExpression="ClaimantNa
</asp:boundfield>
<asp:checkboxfield DataField="IsProblemQuesti
</asp:checkboxfield>
<asp:checkboxfield DataField="IsComment" HeaderText="IsComment" ReadOnly="True" SortExpression="IsComment"
</asp:checkboxfield>
<asp:boundfield DataField="ProblemTitle" HeaderText="ProblemTitle" ReadOnly="True" SortExpression="ProblemTit
</asp:boundfield>
<asp:boundfield DataField="ProblemDescript
</asp:boundfield>
<asp:boundfield DataField="Attachment" HeaderText="Attachment" ReadOnly="True" SortExpression="Attachment
</asp:boundfield>
<asp:boundfield DataField="TeamMemberName"
</asp:boundfield>
<asp:boundfield DataField="solution" HeaderText="solution" SortExpression="solution">
</asp:boundfield>
<asp:boundfield DataField="KnowledgeBaseNo
</asp:boundfield>
<asp:commandfield ShowEditButton="True" ShowInsertButton="True">
</asp:commandfield>
</Fields>
<HeaderStyle BackColor="Tan" Font-Bold="True" />
<EditRowStyle BackColor="PaleGoldenrod" ForeColor="Black" />
<AlternatingRowStyle BackColor="PaleGoldenrod" />
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:HelpDesk
<SelectParameters>
<asp:controlparameter ControlID="GridView1" Name="problemStatusId" PropertyName="SelectedValu
</SelectParameters>
<UpdateParameters>
<asp:parameter Name="KnowledgeBaseNotes" Type="String" />
<asp:parameter Direction="InputOutput" Name="problem_solution_id"
<asp:parameter Name="ProblemStatusID" Type="Int32" />
<asp:parameter Name="Solution" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
Using the same debug point, see if there is anything in the e.OldValues property (or if it even exists in DetailsView1_ItemUpdated() ). If it doesn't then we'll take a sure route that I KNOW will work... it just requires more hands-on coding than you might be used to.
Also, we know for certain that the message.To.Add() will error; that is fine. The objective is to see if there's anything in the e.OldValues property.
Let me know what happens.
Also, we know for certain that the message.To.Add() will error; that is fine. The objective is to see if there's anything in the e.OldValues property.
Let me know what happens.
ASKER
azarc3,
I really didnt get you what you have mentioned above, I am new to .net programming. Can you please elaborate it :(
I really didnt get you what you have mentioned above, I am new to .net programming. Can you please elaborate it :(
No problem at all. I apologize for assuming otherwise.
Going back to your earlier snippets (and combining elements from them), here's what I believe you need to do. If this doesn't work then we'll attack this a different way that I know for a fact will work. I don't want to have to go that route because it might be a little daunting for you. Regardless, I believe I've got it this time...
If you get errors on any of the fieldnames please make sure that casing is the same in both the DetailsView1_ItemUpdated() method and the DetailsView1 control.
Going back to your earlier snippets (and combining elements from them), here's what I believe you need to do. If this doesn't work then we'll attack this a different way that I know for a fact will work. I don't want to have to go that route because it might be a little daunting for you. Regardless, I believe I've got it this time...
If you get errors on any of the fieldnames please make sure that casing is the same in both the DetailsView1_ItemUpdated()
protected void DetailsView1_ItemUpdated(Object sender, DetailsViewUpdatedEventArgs e)
{
string problemID = (string)e.Keys["ProblemStatusId"];
string userName = (string)e.OldValues["UserName"];
string userEmail = (string)e.OldValues["UserEmail"];
string userLocation = (string)e.OldValues["UserLocation"];
string userPhone = (string)e.OldValues["UserPhone"];
string ocd = (string)e.OldValues["ocd"];
string DepartmentName = (string)e.OldValues["DepartmentName"];
string UserNH = (string)e.OldValues["UserNH"];
string UserSSN = (string)e.OldValues["UserSSN"];
string IsRepresentativeInvolved = (string)e.OldValues["IsRepresentativeInvolved"];
string RepresentativeSSN = (string)e.OldValues["RepresentativeSSN"];
string RepresentativeZipCode = (string)e.OldValues["RepresentativeZipCode"];
string OrganizationName = (string)e.OldValues["OrganizationName"];
string ClaimantName = (string)e.OldValues["ClaimantName"];
string IsProblemQuestion = (string)e.OldValues["IsProblemQuestion"];
string IsComment = (string)e.OldValues["IsComment"];
string ProblemTitle = (string)e.OldValues["ProblemTitle"];
string ProblemDescription = (string)e.OldValues["ProblemDescription"];
string Attachment = (string)e.OldValues["Attachment"];
string TeamMemberName = (string)e.OldValues["TeamMemberName"];
string solution = (string)e.NewValues["solution"];
string KnowledgeBaseNotes = (string)e.NewValues["KnowledgeBaseNotes"];
MailMessage message = new MailMessage();
message.From = new MailAddress("shruthi.andem@ssa.gov", "System E-mail");
message.To.Add(new MailAddress(userEmail, userName));
message.Subject = "Problem submission";
message.Body =
"Name: " + userName + "\n" +
"Email: " + userEmail + "\n" +
"Location: " + userLocation + "\n" +
"Phone: " + userPhone + "\n" +
"DOC: " + ocd + "\n" +
"ProblemTitle: " + ProblemTitle + "\n" +
"solution: " + solution + "\n" +
"KnowledgeBaseNotes: " + KnowledgeBaseNotes + "\n" +
"ProblemID: " + problemID;
SmtpClient client = new SmtpClient("!!!", 25);
client.Credentials = new NetworkCredential(SmtpUserName, SmtpUserPass);
client.EnableSsl = true;
client.Send(message);
}
Just an FYI...
Although it doesn't tell us exactly how to address your problem, here's an article to read (when you get a chance) to learn a bit more about the DetailsView control: http://msdn.microsoft.com/en-us/library/ms227560(VS.80).aspx.
Don't try to read it all at once. Even with my couple of years of experience I'll usually read parts of them a few times and then come back and read it all again.
Although it doesn't tell us exactly how to address your problem, here's an article to read (when you get a chance) to learn a bit more about the DetailsView control: http://msdn.microsoft.com/en-us/library/ms227560(VS.80).aspx.
Don't try to read it all at once. Even with my couple of years of experience I'll usually read parts of them a few times and then come back and read it all again.
ASKER
Thanks azarc I will definately look at it and try to execute it on monday as I am off this weekend.
ASKER
azarc,
After trying the above code I am still receiving the error :(
Exception Details: System.InvalidCastExceptio n: Unable to cast object of type 'System.Int32' to type 'System.String'.
Source Error:
Line 39: string problemID = (string)e.Keys["ProblemSta tusId"];
Line 40:
Line 41: string userName = (string)e.OldValues["UserN ame"];
After trying the above code I am still receiving the error :(
Exception Details: System.InvalidCastExceptio
Source Error:
Line 39: string problemID = (string)e.Keys["ProblemSta
Line 40:
Line 41: string userName = (string)e.OldValues["UserN
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Azarc,
Thanks a lot for the help , it worked like a charm :)
I really appreciate your help and time.
Thanks a lot for the help , it worked like a charm :)
I really appreciate your help and time.
ASKER
azarc,
sorry for the trouble again, but I am having problem again.
I tried to add multiline in my solution and Knowledgebasenotes, I am not able to retrieve those values at all...
<asp:templatefield HeaderStyle-Wrap="true" HeaderText="Solution:">
<EditItemTemplate>
<asp:TextBox TextMode="MultiLine" Rows="5" Columns="50" ID="solution" runat="server" Text='<%# Bind("Solution") %>'>
</asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblSolution" runat="server" Text='<%# Eval("Solution") %>'>
</asp:Label>
</ItemTemplate>
</asp:templatefield>
<asp:templatefield HeaderStyle-Wrap="true" HeaderText="Knowledge Base Notes:">
<EditItemTemplate>
<asp:TextBox TextMode="MultiLine" Rows="5" Columns="50" ID="txtKnowledgeBaseNotes" runat="server" Text='<%# Bind("KnowledgeBaseNotes") %>'>
</asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblKnowledgeBaseNotes" runat="server" Text='<%# Eval("KnowledgeBaseNotes") %>'>
</asp:Label>
</ItemTemplate>
</asp:templatefield>
sorry for the trouble again, but I am having problem again.
I tried to add multiline in my solution and Knowledgebasenotes, I am not able to retrieve those values at all...
<asp:templatefield HeaderStyle-Wrap="true" HeaderText="Solution:">
<EditItemTemplate>
<asp:TextBox TextMode="MultiLine" Rows="5" Columns="50" ID="solution" runat="server" Text='<%# Bind("Solution") %>'>
</asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblSolution" runat="server" Text='<%# Eval("Solution") %>'>
</asp:Label>
</ItemTemplate>
</asp:templatefield>
<asp:templatefield HeaderStyle-Wrap="true" HeaderText="Knowledge Base Notes:">
<EditItemTemplate>
<asp:TextBox TextMode="MultiLine" Rows="5" Columns="50" ID="txtKnowledgeBaseNotes"
</asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblKnowledgeBaseNotes"
</asp:Label>
</ItemTemplate>
</asp:templatefield>
No trouble! Have you reverted back to "single" mode to verify this is actually the problem? I've never run across that before, so we'll have to research it.
Some preliminary looking; see if this one helps at all...
https://www.experts-exchange.com/questions/23313709/Extracting-data-from-detailsview-textbox-in-code-behid-for-additional-processing.html
https://www.experts-exchange.com/questions/23313709/Extracting-data-from-detailsview-textbox-in-code-behid-for-additional-processing.html
try creating a new SMTPClient(string host) (1st overload) to tell it which SMTP server to use.
You may then get authentication errors, depending how the SMTP server is set up. If this is the case, create a new credential object (System.Net.NetworkCredent
then set the credentials property of the SMTP Client = the new credentials
Hope that helps