Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Dear Friends i am try to code a site which can provide the chating option, and also status update
i have code for status update one multi line textbox, one file upload and one button , if we enter ant text and post it will display but if i post ant image than this code will not work , i have past all my code here please help me .
This is the Design page code:

XML
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="LatestUpdates.ascx.cs" Inherits="Controls_Latest" %>
<style type="text/css">
    .styleLatestUpdates
    {
        width: 400px;
    }
    .stylePost
    {
        width: 98%;
        height: 90px;
    }
    .styleComment
    {
        width: 103px;
    }
    .stylePostPic
    {
        width: 110px;
        vertical-align: top;
    }
    </style>
<table style="width: 550px" align="center">
    <tr>
        <td align="left" style="padding-left: 10px">
            <asp:Label ID="lblName" runat="server" Font-Bold="True" Font-Names="Georgia" Font-Size="Large"></asp:Label>
        </td>
        <td align="right">
            <asp:LinkButton ID="btnAddAsFriend" runat="server" Text="Add As Friend" Font-Bold="True"
                Font-Italic="True" OnClick="btnAddAsFriend_Click"></asp:LinkButton>
            <br />
        </td>
    </tr>
</table>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <table align="center" cellpadding="0" cellspacing="0" class="styleLatestUpdates">
            <tr>
                <td>
                    <table style="width: 550px">
                        <tr>
                            <td align="left">
                                <panel runat="server" id="pnlStatus">
                                <asp:TextBox ID="txtWhatsOnYourHeart" runat="server" Height="59px" TextMode="MultiLine" Width="543px"></asp:TextBox>
                                <br />
                                 <asp:Button ID="btnPost" runat="server" BackColor="#CCCCCC" BorderColor="#CCCCCC" BorderStyle="Ridge" BorderWidth="1px" Font-Bold="True" ForeColor="#333333" OnClick="btnPost_Click"
                                    Text="Post" Width="52px" />
                                  <asp:FileUpload ID="FileUpload1" runat="server" />                                 <asp:UpdateProgress ID="ProgressBar" runat="server">
                                    <ProgressTemplate>
                                        <asp:Image ID="Image1" runat="server" ImageUrl="~/images/loading.gif" />
                                    </ProgressTemplate>
                                </asp:UpdateProgress>
                                </panel>
                            </td>
                        </tr>
                    </table>
                    <hr />
                </td>
            </tr>
            <tr>
                <td>
                    <asp:DataList ID="dlPosts" runat="server" Width="550px">
                        <ItemTemplate>
                            <div>
                                <table cellpadding="0" cellspacing="0" class="stylePost">
                                    <tr>
                                        <td class="stylePostPic" rowspan="2" align="center">
                                            <asp:ImageButton ID="YourPic" runat="server" BorderColor="Black" BorderStyle="Ridge"
                                                BorderWidth="1px" Height="60px" ImageUrl='<%# "ImageHandler.ashx?RegisterId="+ Eval("RegisterId") %>'
                                                Width="60px" OnClick="YourPic_Click" CommandArgument='<%#Bind("RegisterId") %>' />
                                        </td>
                                        <td valign="top" align="left">
                                            <asp:Label runat="server" ID="lblName" ForeColor="Blue" Font-Bold="True" Font-Italic="True">

                                            <%# DataBinder.Eval(Container.DataItem, "Name")%> &nbsp;Posted:</asp:Label>
                                             <div style="width: 300px">
                                                <%# DataBinder.Eval(Container.DataItem, "Post")%>
                                            </div>
                                            <div style="width:300px">
                                                <%#DataBinder.Eval(Container.DataItem,"img") %>
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td align="right" valign="bottom">
                                            <asp:Label runat="server" ID="lblPostedOn" ForeColor="Black" Font-Italic="True" Font-Size="Small">

                                            Posted On: <%# DataBinder.Eval(Container.DataItem, "PostDate")%>


                                            </asp:Label>
                                        </td>
                                    </tr>
                                </table>
                                <br />
                                <hr />
                            </div>
                        </ItemTemplate>
                    </asp:DataList>
                </td>
            </tr>
        </table>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="btnPost" EventName="Click" />
    </Triggers>
</asp:UpdatePanel>



This is the logical post button code :

C#
String ss, ss1;
  protected void btnPost_Click(object sender, EventArgs e)
  {
      //if (FileUpload1.HasFile)
      //{
         // ss = Server.MapPath("img");
          //ss = ss+"/" +FileUpload1.FileName;
          ss1 = "~\\img\\" + FileUpload1.FileName.ToString();
          FileUpload1.PostedFile.SaveAs(Server.MapPath(ss1));

          string PostDate = DateTime.Now.ToLongDateString();
          string InsertPostquery = "Insert into Posts (Post,FromId,ToId,PostDate,img) values('" + txtWhatsOnYourHeart.Text + "','" + Convert.ToInt32(Session["UserId"]) + "','" + Convert.ToInt32(Session["CurrentProfileId"]) + "','" + PostDate + "','" + ss1 + "')";
          Database.InsertData(InsertPostquery);
          LatestUpdates();
          txtWhatsOnYourHeart.Text = string.Empty;
      //}
      //else
      //{
      //    string PostDate = DateTime.Now.ToLongDateString();
      //    string InsertPostquery = "Insert into Posts (Post,FromId,ToId,PostDate,img)values('" + txtWhatsOnYourHeart.Text + "','" + Convert.ToInt32(Session["UserId"]) + "','" + Convert.ToInt32(Session["CurrentProfileId"]) + "','" + PostDate + "','" + ss1 + "')";
      //    Database.InsertData(InsertPostquery);
      //    LatestUpdates();
      //    txtWhatsOnYourHeart.Text = string.Empty;
      // }
  }
Posted
Comments
thatraja 17-Apr-14 9:17am    
/* but if i post ant image than this code will not work */
What happened? any error?
Member 10273293 18-Apr-14 1:55am    
this is my problem dear , when i post any image it will not work ?
no error message will be display
thatraja 23-Apr-14 2:57am    
what's the datatype of column img?
Member 10273293 23-Apr-14 5:35am    
varchar
thatraja 23-Apr-14 6:09am    
where's the code for loading image? Update your question with more details

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900