Insert data to Database not working after ASP.Net UpdatePanel PostBack

Last Reply one month ago By micah

Posted one month ago

After posting data Updata panel not updating to show data

 

<asp:UpdatePanel ID="updResult" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:DataList ID="GetMergedAll" runat="server" DataKeyName="Id" OnItemCommand="GetMergedAll_ItemCommand"
            OnItemDataBound="GetMergedAll_ItemDataBound">
            <ItemTemplate>
                <asp:Label ID="Label36" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"Name") %>'
                    ForeColor="#999999" />
                <asp:Label ID="Label36" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"Title") %>'
                    ForeColor="#999999" />
            </ItemTemplate>
        </asp:DataList>
    </ContentTemplate>
</asp:UpdatePanel>

 

protected void linkpost_Click(object sender, EventArgs e)
{
    if (this.Page.User.Identity.IsAuthenticated)
    {
        string username = this.Page.User.Identity.Name;
        {
            string tendString = TextBixcomment.Text.Trim();
            string strname = ""; // ADDED
            if (FileUploadImage.HasFile)
            {
                strname = FileUploadImage.FileName.ToString();
                FileUploadImage.PostedFile.SaveAs(Server.MapPath("~/UserImage/") + strname);
            } // <-- ADDED SO THAT WE JUST SAVE THE FILE IF THE FILE IS UPLOADED

            // THEN UNCHANGED WE SAVE THE DATA TO THE DB

            string str = ConfigurationManager.ConnectionStrings["Conn"].ConnectionString;
            string getADPOST = "Insert INTO USERPost (UserName,ContentPost,ImageName1) values (@UserName,@ContentPost,@ImageName1)";
            // string getADPOST = "Insert INTO CommunityFollow  (MyUserName,CommunityStatus) values (@MyUserName,1)";
            using (SqlConnection con = new SqlConnection(str))
            {

                using (SqlCommand cmd = new SqlCommand(getADPOST, con))
                {
                    // Get Filename from fileupload control
                    //   string filename = Path.GetFileName(FileUploadImage.PostedFile.FileName);
                    //  Save images into Images folder
                    //    Server.MapPath("~/UserImage/" + FileUploadImage.FileName);

                    //  cmd.Parameters.AddWithValue("@ImageName1", filename);
                    //    cmd.Parameters.AddWithValue("@ImageName1", "~/UserImage/" + filename);
                    cmd.Parameters.AddWithValue("@ContentPost", TextBixcomment.Text.Trim());
                    cmd.Parameters.AddWithValue("@UserName", username);

                    cmd.Parameters.AddWithValue("@ImageName1", strname);
                    //cmd.Parameters.AddWithValue("@VideoName", strname);
                    con.Open();
                    cmd.ExecuteNonQuery();
                    con.Close();

                    //  Response.Redirect("Home.aspx");
                    string message = "Post submitted successfully.";
                    string script = "window.onload = function(){ alert('";
                    script += message;
                    script += "')};";
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "SuccessMessage", script, true);
                }
            }

        }
        // } ONE OF THIS DISAPPEARS AS WE CLOSED THE IF BLOCK MUCH EARLIER
    }
}

 

 

You are viewing reply posted by: micah one month ago.
Posted one month ago

i did it this way for procedure it worked

 

      this.GetData();

    }

    private void GetData()
    {
        string str = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
        string GetData = "GetUserPOSTS";
        using (SqlConnection con = new SqlConnection(str))
        {
            con.Open();
            using (SqlCommand cmd = new SqlCommand(GetData, con))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                // cmd.Parameters.AddWithValue("@Name", Request.QueryString["Id"].ToString());
                cmd.Parameters.AddWithValue("@UserName", username);
                cmd.Parameters.AddWithValue("@Id", Id);

                SqlDataAdapter sda = new SqlDataAdapter(cmd);
                DataTable dt = new DataTable();
                sda.Fill(dt);
                GetMergedAll.DataSource = dt;
                GetMergedAll.DataBind();

            }

        }
    }

 

I agree, here is the link: http://e-iceblue.com/free-api