Fix button onclick behind code with Formview

151 views Asked by At

I make i my own mail interface system into my application and since the user click on Repsendbtn into listview called " viewmsgView " then he will hide the " viewmsgView" and show " repmsgform " and bind the data into repmsgform depending on mailno. What i am facing is as you all know that cant reach controls into listview or formview and the Repsendbtn is inside the formview and it will depend on others controls to process the below behind code but i am getting red-line under the controls id with message: " The name 'Label' does not exist in the current context " so how i can solve this case and make the button code work smoothly. Its may really not so clear my post, so i decide to make record screen which i hope will make it easily to explain what i am looking for. Please click on the below link and have a look of my screen record where i explain what i am looking for:

https://www.youtube.com/watch?v=OMKp7b6iMJ8&feature=youtu.be

<asp:FormView ID="repmsgform" runat="server"  DataKeyNames="mailno" Width="100%" >
                          <ItemTemplate>

                      <div>
                      <table class="table table-bordered" style="margin-left:0px;" >
                     <tbody>
                        <tr>
                            <td style="border-collapse:collapse; border:2px solid white; color:#333333; background-color:#f0f0f0;">
                                Ads Number:
                            </td>
                            <td >
                                <asp:Label ID="adsnummsglbl" runat="server" Text='<%# Bind("AdsID") %>' ></asp:Label>
                            </td>
                        </tr>
                        <tr>
                            <td td style="border-collapse:collapse; border:2px solid white; color:#333333; background-color:#f0f0f0;">
                                Message Title:
                            </td>
                            <td>
                                <asp:Label ID="adstitmsglbl" runat="server" Color="#669900" Text='<%# Bind("Mestitle") %>'></asp:Label>
                            </td>
                        </tr>

                        <tr>
                            <td td style="border-collapse:collapse; border:2px solid white; color:#333333; background-color:#f0f0f0;">
                                From:&nbsp;&nbsp;
                            </td>
                            <td>
                                <asp:Label ID="Reciverlblnme" runat="server" Text='<%# Bind("Receiver") %>'></asp:Label>
                            </td>
                        </tr>
                        <tr>

                            <td style="border-collapse:collapse; border:2px solid white; color:#333333; background-color:#f0f0f0;">To:</td>
                            <td> <asp:Label ID="Tolbl" runat="server" Text='<%# Bind("sender") %>'></asp:Label></td>
                        </tr>

                           </tbody>
                    </table>

                      <div class="form-group">
                          <asp:Label ID="Label12" runat="server" Text="Label" CssClass="col-md-3 control-label">Your Message:</asp:Label>

                                <div class="col-md-9">
                                <asp:TextBox ID="TextBox1" runat="server" Height="150px" TextMode="multiline" CssClass="form-control" 
                                    ></asp:TextBox>
                                    </div>
                                    </div>

                                <asp:Label ID="msgsentlbl" runat="server" Font-Size="Medium" ForeColor="#669900"></asp:Label>

                            <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
          <div class="pull-right">
                                <asp:Button ID="Closebtn" runat="server" Text="Close" 
                                     CssClass="btn btn-default" onclick="Closebtn_Click"/>
                               &nbsp;&nbsp;&nbsp;&nbsp;
                      <asp:Button runat="server" ID="Repsendbtn" Text="Send" CssClass="btn btn-primary" 
                                    onclick="Repsendbtn_Click"/></div>
                      </div></div>

                   </ItemTemplate>
                          </asp:FormView>







 protected void Repsendbtn_Click(object sender, EventArgs e)
    {

        if (Session["UsrNme"] != null)
        {

            using (SqlConnection cn = new SqlConnection(sc))
            {

                string SendMsgSQL = @"INSERT mails [CVs] ([Message], [Mestitle], [AdsID], [Date], [Receiver], [sender])
        VALUES (@Message, @Mestitle, @AdsID , @Date, @Receiver, @sender)";

                using (SqlCommand SendMsgcmd = new SqlCommand(SendMsgSQL, cn))
                {

                    cn.Open();
                    var user = Session["UsrNme"];

                    SendMsgcmd.Parameters.AddWithValue("@sender", user);
                    SendMsgcmd.Parameters.AddWithValue("@Message", TextBox1.Text);
                    SendMsgcmd.Parameters.AddWithValue("@Mestitle", adstitmsglbl.Text);
                    SendMsgcmd.Parameters.AddWithValue("@AdsID", adsnummsglbl.Text);
                    SendMsgcmd.Parameters.AddWithValue("@Date", DateTime.Now);
                    SendMsgcmd.Parameters.AddWithValue("@Receiver", Reciverlblnme.Text);

                    SendMsgcmd.ExecuteNonQuery();

                    Response.Redirect("User panel.aspx");
                }
            }
        }

        else
        {
            // Consider throwing an error (if these fields are required)
        }

    }
0

There are 0 answers