Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8186775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:20:23+00:00 2026-06-07T02:20:23+00:00

In a web-based ASP.NET suggestions box program, the Admin will be able to see

  • 0

In a web-based ASP.NET suggestions box program, the Admin will be able to see all suggestions listed in a GridView control with the username of the owner. In the last column of the GridView, the status will be listed there. When the Admin clicks on the status of one of these suggestion, a new pop-up window (asp.net ajax ModalPopUpExtender) will be appeared with listing all the possible status such as: actioned, approved… etc. And when the Admin selects one of these status, the status of the suggestion will be updated in the database. Everything works fine. What I want to do now is when the user updates the status of anyone of the suggestions, an email notification will be sent to the owner regarding the update of status of his suggestion.

I already wrote the Mail function but I don’t know why it does not send any email and I am getting this error while debugging the code:

Use of unassigned local variable ‘description’

I already assigned it to the value of the [Description] column in the database but I don’t know why I am getting this error.

Could anyone help me with this?

I am really struggling with getting the username of that updated suggestion. FYI, I have the following database design:

Employee Table: Username, Name... 
SafetySuggestionsLog: ID, Title, Description, Username, StatusID 
SafetySuggestionsStatus: ID, Status

ASP.NET code:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
                        AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="ID" 
                        width="900px" CssClass="mGrid" 
                        DataSourceID="SqlDataSource1" 
                        OnRowDataBound="GridView1_RowDataBound">
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" CssClass="alt" />
            <HeaderStyle Font-Bold = "True" ForeColor="Black" Height="20px"/> 
            <Columns>
                <asp:BoundField DataField="ID" HeaderText="No." InsertVisible="False" 
                    ReadOnly="True" SortExpression="ID" />
                <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
                <asp:BoundField DataField="Description" HeaderText="Description" 
                    SortExpression="Description" />
                <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                <asp:BoundField DataField="Username" HeaderText="Username" 
                    SortExpression="Username" />
                <asp:BoundField DataField="DivisionShortcut" HeaderText="Division" 
                    SortExpression="DivisionShortcut" />
                <asp:BoundField DataField="Type" HeaderText="Type" SortExpression="Type" />

                <%-- This to make status be opened and edited through the Ajax ModalPopUp Window --%>
                <asp:TemplateField HeaderText="Status">
                    <ItemTemplate>
                        <asp:LinkButton runat="server" ID="lnkSuggestionStatus" Text='<%#Eval("Status")%>'
                                        OnClick="lnkSuggestionStatus_Click">
                        </asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>

                <%--<asp:HyperLinkField HeaderText="Status" 
                    SortExpression="Status" />--%>
            </Columns>
            <RowStyle HorizontalAlign="Center" />
        </asp:GridView>

        <asp:Button runat="server" ID="btnModalPopUp" style="display:none" />

        <AjaxToolkit:ModalPopUpExtender ID="modalPopUpExtender1"
                                        runat="server" 
                                        TargetControlID="btnModalPopUp" 
                                        PopupControlID="pnlPopUp" 
                                        BackgroundCssClass="popUpStyle"
                                        PopupDragHandleControlID="panelDragHandle" 
                                        OkControlID="OKButton">
        </AjaxToolkit:ModalPopUpExtender>

        <asp:HiddenField ID="HiddenField1" runat="server"/>

        <asp:Panel runat="server" ID="pnlPopUp" CssClass="popUpStyle">

                    <asp:RadioButtonList ID="StatusList" runat="server" RepeatColumns="1" RepeatDirection="Vertical"
                                            RepeatLayout="Table" TextAlign="Right" DataSourceID="SuggestionStatusDataSource"
                                            DataTextField="Status" DataValueField="ID">
                        <asp:ListItem id="option1" runat="server" Value="ACTIONED" />
                        <asp:ListItem id="option2" runat="server" Value="APPROVED" />
                        <asp:ListItem id="option3" runat="server" Value="PENDING" />
                        <asp:ListItem id="option4" runat="server" Value="TRANSFERRED" />
                    </asp:RadioButtonList>
                    <asp:SqlDataSource ID="SuggestionStatusDataSource" runat="server"
                                        ConnectionString="<%$ ConnectionStrings:testConnectionString %>"
                                        SelectCommand="SELECT * FROM [SafetySuggestionsStatus]"></asp:SqlDataSource>

                    <asp:Button ID="confirmButton" runat="server" Text="Confirm" 
                                OnClientClick="javascript:return confirm('Are you sure you want to send an email notification about the safety suggestion to the owner?')" 
                                OnClick="btnSendStatus_Click" />

            <asp:Button ID="OKButton" runat="server" Text="Close" />
        </asp:Panel>
        </ContentTemplate>
        </asp:UpdatePanel>

Code-Behind:

protected void lnkSuggestionStatus_Click(object sender, EventArgs e)
    {
        LinkButton lnkSuggestionStatus = sender as LinkButton;

        //var safetySuggestionsId = 

        //get reference to the row selected 
        GridViewRow gvrow = (GridViewRow)lnkSuggestionStatus.NamingContainer;

        //set the selected index to the selected row so that the selected row will be highlighted
        GridView1.SelectedIndex = gvrow.RowIndex;

        //This HiddenField used to store the value of the ID
        HiddenField1.Value = GridView1.DataKeys[gvrow.RowIndex].Value.ToString();
        //ViewState["Username"] = gvrow.Cells[4].Text;

        //show the modalPopUp
        modalPopUpExtender1.Show();
    }

    public void btnSendStatus_Click(object sender, EventArgs e) {
        //get the ID of the selected suggestion/row
        var statusID = StatusList.SelectedValue;
        var safetySuggestionsID = HiddenField1.Value;

        string connString = "Data Source=localhost\\sqlexpress;Initial Catalog=psspdbTest;Integrated Security=True";
        //For updating the status of the safety suggestion
        string updateCommand = "UPDATE SafetySuggestionsLog SET StatusID= @statusID where ID=@SafetySuggestionsID";
        using (SqlConnection conn = new SqlConnection(connString))
        {
            conn.Open();
            using (SqlCommand cmd = new SqlCommand(updateCommand, conn))
            {
                cmd.Parameters.AddWithValue("@statusID", Convert.ToInt32(statusID));
                cmd.Parameters.AddWithValue("@SafetySuggestionsID", Convert.ToInt32(HiddenField1.Value));
                cmd.ExecuteNonQuery();
            }
            //reset the value of hiddenfield
            HiddenField1.Value = "-1";
        }

        GridView1.DataBind();


        SendSuggestionStatusToUser(safetySuggestionsID);
    }

    protected void SendStatusByEmail(string toAddresses, string fromAddress, string MailSubject, string MessageBody, bool isBodyHtml)
    {
        SmtpClient sc = new SmtpClient("MAIL.Aramco.com");
        try
        {
            MailMessage msg = new MailMessage();
            msg.From = new MailAddress("pssp@aramco.com", "PMOD Safety Services Portal (PSSP)");

            // In case the mail system doesn't like no to recipients. This could be removed
            //msg.To.Add("pssp@aramco.com");

            msg.Bcc.Add(toAddresses);
            msg.Subject = MailSubject;
            msg.Body = MessageBody;
            msg.IsBodyHtml = isBodyHtml;
            sc.Send(msg);
        }
        catch (Exception ex)
        {
            throw ex;
        }

    }

    protected void SendSuggestionStatusToUser(string suggestionID)
    {
        string connString = "Data Source=localhost\\sqlexpress;Initial Catalog=psspdbTest;Integrated Security=True";

        string safetySuggestionID = suggestionID.ToString();
        //string username = ViewState["Username"].ToString();

        //The following connection is to get the username of the suggestion Owner
        //and append (@aramco.com) to it.
        using (SqlConnection conn = new SqlConnection(connString))
        {
            var sbEmailAddresses = new System.Text.StringBuilder(2000);

            //initiate the varibles that will be retreived from the database
            string username;
            string description;
            string status;

            // Open DB connection.
            conn.Open();

            string cmdText2 = @"SELECT Username, Description, Status FROM dbo.SafetySuggestionsLog SSL INNER JOIN SafetySuggestionsStatus SSS
                                ON (SSL.StatusID = SSS.ID) WHERE (SSL.ID = @safetySuggestionID)";
            using (SqlCommand cmd = new SqlCommand(cmdText2, conn))
            {
                cmd.Parameters.AddWithValue("@SafetySuggestionID", Convert.ToInt32(HiddenField1.Value));
                SqlDataReader reader = cmd.ExecuteReader();
                if (reader != null)
                {
                    if (reader.Read())
                    {
                        username = reader["Username"].ToString();
                        description = reader["Description"].ToString();
                        status = reader["Status"].ToString();
                        sbEmailAddresses.Append(username).Append("aramco.com");
                    }
                }

                var sEMailAddresses = sbEmailAddresses.ToString();
                string body = @"Good day, &lt;br /&gt;&lt;br /&gt;
                                <b> We just would like to notify you that your following safety suggestion: </b>"
                                    + description +
                                    @"&lt;br /&gt;&lt;br /&gt;
                            has been.
                            &lt;br /&gt; &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;
                            This email was generated using the &lt;a href='http://pmv/pssp/Default.aspx'&gt;PMOD Safety Services Portal (PSSP) &lt;/a&gt;. 
                            Please do not reply to this email.
                            ";
                SendStatusByEmail(sbEmailAddresses.ToString(), "", "Notification of Your Safety Suggestion", body, true);
                sbEmailAddresses.Clear();
                reader.Close();


            }

            conn.Close();
        }
    }

Note: I know that I should not post a lengthy code here, but because I want to explain to you my work and to get your help.

UPDATE:

I modified my code regarding assigning the variables to NULL and when I debugged the code, I found that the reader doesn’t work and it did not read the following:

if (reader != null)
                {
                    if (reader.Read())
                    {
                        username = reader["Username"].ToString();
                        description = reader["Description"].ToString();
                        status = reader["Status"].ToString();
                        sbEmailAddresses.Append(username).Append("@aramco.com");
                    }
                }

UPDATE 2:

In the SendSuggestionStatusToUser(string suggestionID) method, I added break point to the following line:

string safetySuggestionID = suggestionID.ToString();

and I added break point to the following line:

cmd.Parameters.AddWithValue("@safetySuggestionID", Convert.ToInt32(HiddenField1.Value));

And I found that for the first one, the safetySuggestionID got the data from the passed value. However, for the second one the value of (HiddenField1.Value)is -1 and I don’t know why. Also, I added break points to each one of the following lines:

SqlDataReader reader = cmd.ExecuteReader();
                if (reader != null)
                {
                    if (reader.Read())
                    {
                        username = reader["Username"].ToString();
                        description = reader["Description"].ToString();
                        status = reader["Status"].ToString();
                        sbEmailAddresses.Append(username).Append("@aramco.com");
                    }
                }

And the debugger did not go through them while debugging them. It goes directly to

var sEMailAddresses = sbEmailAddresses.ToString();

And I don’t know why. Any idea? Could you please help me?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T02:20:25+00:00Added an answer on June 7, 2026 at 2:20 am

    The problem is that the variables username, description and status in the SendSuggestionStatusToUser function are not definitely assigned at the point you are using them.

    That is, if reader == null they will not have a value.

    Since you are using description to construct the value of body later on, it could be null (and was never assigned to). That’s the meaning of the error.

    One simple change is to definitely assign them – either to null or to an empty string:

    string username = null;
    string description = null;
    string status = string.Empty;
    

    Update:

    I have now notices how you are constructing your email addresses:

    sbEmailAddresses.Append(username).Append("aramco.com");
    

    Unless the username ends with a @, this will not produce a valid email address. There is also no separator between email addresses, so I don’t know how this would ever work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a new ASP.NET developer and I am developing a web-based suggestions box
I am creating a web based email client using c# asp.net. What is confusing
I am trying to use third-party web service (php-based) in asp.net c# application, and
Let me share the following scenario: I have a ASP.NET intranet Web-based application that
I'm building an ASP .NET 2.0 (C#) based web application, which is primarily intended
I am working with a Web application, based on Asp.Net 3.5 and WSS 3.0
I am working on an asp.net web site that is based upon a single
We are developing a REST based application using Visual Studio 2010, using asp.net web
In our asp.net mvc based web site, we want to allow users to manage
We've been working with ASP.Net MVC2 based web app. We're using DataAnnotations for model

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.