ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2017 www.aspforums.com. All rights reserved.Insert data to Database not working after ASP.Net UpdatePanel PostBackHi @micah,<br />Please try the following<br /><br /><a href = 'link(Threads/669114/jQuery-DataTable-plugin-not-working-after-ASPNet-UpdatePanel-PostBack/)'>jQuery DataTable plugin not working after ASP.Net UpdatePanel PostBack</a><br /><br />It might help you.<br /><br />Cheers Andrea.http://www.aspforums.net/Threads/105725/Insert-data-to-Database-not-working-after-ASPNet-UpdatePanel-PostBack/http://www.aspforums.net/Threads/105725/Insert-data-to-Database-not-working-after-ASPNet-UpdatePanel-PostBack/Mon, 09 Jan 2017 11:45:42 GMTInsert data to Database not working after ASP.Net UpdatePanel PostBack<p>Hi <a class="username" rel="micah"> micah</a>,</p> <p>I did some modification in your code. So please refer the below code.</p> <p><span style="text-decoration: underline;">HTML</span></p> <pre class="brush: html">&lt;form id=&#34;form1&#34; runat=&#34;server&#34;&gt; &lt;div&gt; &lt;asp:FileUpload ID=&#34;FileUploadImage&#34; runat=&#34;server&#34; /&gt; &lt;asp:TextBox ID=&#34;TextBixcomment&#34; runat=&#34;server&#34; /&gt; &lt;asp:LinkButton ID=&#34;btnSubmit&#34; OnClick=&#34;linkpost_Click&#34; Text=&#34;Submit&#34; runat=&#34;server&#34; /&gt; &lt;asp:ScriptManager runat=&#34;server&#34; /&gt; &lt;br /&gt; &lt;br /&gt; &lt;asp:UpdatePanel ID=&#34;updResult&#34; runat=&#34;server&#34; UpdateMode=&#34;Conditional&#34;&gt; &lt;ContentTemplate&gt; &lt;asp:DataList ID=&#34;GetMergedAll&#34; runat=&#34;server&#34; DataKeyName=&#34;Id&#34; OnItemCommand=&#34;GetMergedAll_ItemCommand&#34; OnItemDataBound=&#34;GetMergedAll_ItemDataBound&#34;&gt; &lt;ItemTemplate&gt; &lt;asp:Label ID=&#34;lblName&#34; runat=&#34;server&#34; Text=&#39;&lt;%#DataBinder.Eval(Container.DataItem,&#34;Name&#34;) %&gt;&#39; ForeColor=&#34;#999999&#34; /&gt; &lt;asp:Label ID=&#34;lblTitle&#34; runat=&#34;server&#34; Text=&#39;&lt;%#DataBinder.Eval(Container.DataItem,&#34;Title&#34;) %&gt;&#39; ForeColor=&#34;#999999&#34; /&gt; &lt;/ItemTemplate&gt; &lt;/asp:DataList&gt; &lt;/ContentTemplate&gt; &lt;/asp:UpdatePanel&gt; &lt;/div&gt; &lt;/form&gt;</pre> <p><span style="text-decoration: underline;">C#</span></p> <pre class="brush: csharp">private string str = ConfigurationManager.ConnectionStrings[&#34;Constring&#34;].ToString(); protected void Page_Load(object sender, EventArgs e) { this.GetData(); } private void GetData() { SqlConnection con = new SqlConnection(str); SqlCommand cmd = new SqlCommand(&#34;SELECT UserName as Name,ContentPost as Title,Id,ImageName1 FROM USERPost1&#34;, con); SqlDataAdapter sda = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); sda.Fill(dt); GetMergedAll.DataSource = dt; GetMergedAll.DataBind(); } 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 = &#34;&#34;; // ADDED if (FileUploadImage.HasFile) { strname = FileUploadImage.FileName.ToString(); FileUploadImage.PostedFile.SaveAs(Server.MapPath(&#34;~/UserImage/&#34;) + strname); } // &lt;-- 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[&#34;Conn&#34;].ConnectionString; string getADPOST = &#34;Insert INTO USERPost(UserName,ContentPost,ImageName1) values (@UserName,@ContentPost,@ImageName1)&#34;; // string getADPOST = &#34;Insert INTO CommunityFollow (MyUserName,CommunityStatus) values (@MyUserName,1)&#34;; 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(&#34;~/UserImage/&#34; + FileUploadImage.FileName); // cmd.Parameters.AddWithValue(&#34;@ImageName1&#34;, filename); // cmd.Parameters.AddWithValue(&#34;@ImageName1&#34;, &#34;~/UserImage/&#34; + filename); cmd.Parameters.AddWithValue(&#34;@ContentPost&#34;, TextBixcomment.Text.Trim()); cmd.Parameters.AddWithValue(&#34;@UserName&#34;, &#34;PETER&#34;); cmd.Parameters.AddWithValue(&#34;@ImageName1&#34;, strname); //cmd.Parameters.AddWithValue(&#34;@VideoName&#34;, strname); con.Open(); cmd.ExecuteNonQuery(); con.Close(); // Response.Redirect(&#34;Home.aspx&#34;); string message = &#34;Post submitted successfully.&#34;; string script = &#34;window.onload = function(){ alert(&#39;&#34;; script += message; script += &#34;&#39;)};&#34;; Page.ClientScript.RegisterStartupScript(this.GetType(), &#34;SuccessMessage&#34;, script, true); } } } // } ONE OF THIS DISAPPEARS AS WE CLOSED THE IF BLOCK MUCH EARLIER } this.GetData(); }</pre> <p><span style="text-decoration: underline;">Screenshot</span></p> <p><span style="text-decoration: underline;"><img src="https://i.imgur.com/lARx8Eo.gif" alt="" width="468" height="356" /></span></p>http://www.aspforums.net/Threads/105725/Insert-data-to-Database-not-working-after-ASPNet-UpdatePanel-PostBack/http://www.aspforums.net/Threads/105725/Insert-data-to-Database-not-working-after-ASPNet-UpdatePanel-PostBack/Tue, 10 Jan 2017 03:17:42 GMTInsert data to Database not working after ASP.Net UpdatePanel PostBack<p>hi please this is the methode i used to fetch the record on page load, i used procedure. So i tried to modify it i couldnt</p> <p>&nbsp;</p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { if (!this.IsPostBack) { username = this.Page.User.Identity.Name; DataTable dt = GetProfile(); GetMergedAll.DataSource = dt; ViewState[&#34;DataTable&#34;] = dt; GetMergedAll.DataSource = dt; GetMergedAll.DataBind(); // if (dt.Rows.Count &gt; 0) { } } } } public DataTable GetProfile() { SqlConnection constr = new SqlConnection(ConfigurationManager.ConnectionStrings[&#34;conn&#34;].ConnectionString); SqlDataAdapter adp = new SqlDataAdapter(&#34;GetUserPOSTS&#34;, constr); adp.SelectCommand.CommandType = CommandType.StoredProcedure; // adp.SelectCommand.Parameters.AddWithValue(&#34;@Email&#34;, username); adp.SelectCommand.Parameters.AddWithValue(&#34;@UserName&#34;, username); adp.SelectCommand.Parameters.AddWithValue(&#34;@Id&#34;, Id); DataTable dt = new DataTable(); // adp.Fill(dt); return dt; } </pre> <p>&nbsp;</p> <p>&nbsp;</p>http://www.aspforums.net/Threads/105725/Insert-data-to-Database-not-working-after-ASPNet-UpdatePanel-PostBack/http://www.aspforums.net/Threads/105725/Insert-data-to-Database-not-working-after-ASPNet-UpdatePanel-PostBack/Tue, 10 Jan 2017 06:21:39 GMTInsert data to Database not working after ASP.Net UpdatePanel PostBack<p>just help me modify your select method to use procedure</p>http://www.aspforums.net/Threads/105725/Insert-data-to-Database-not-working-after-ASPNet-UpdatePanel-PostBack/http://www.aspforums.net/Threads/105725/Insert-data-to-Database-not-working-after-ASPNet-UpdatePanel-PostBack/Tue, 10 Jan 2017 06:54:41 GMTInsert data to Database not working after ASP.Net UpdatePanel PostBack<p>Hi <a class="username" rel="micah"> micah</a>,</p> <p>Please refer the below link read carefully.First understand the store procedure than Implement in your project.</p> <h1 class="header"><a title="Single Stored Procedure for Select Insert Update Delete in SQL Server'a" href="http://www.aspsnippets.com/Articles/Single-Stored-Procedure-for-Select-Insert-Update-Delete-in-SQL-Server.aspx">Single Stored Procedure for Select Insert Update Delete in SQL Server</a></h1>http://www.aspforums.net/Threads/105725/Insert-data-to-Database-not-working-after-ASPNet-UpdatePanel-PostBack/http://www.aspforums.net/Threads/105725/Insert-data-to-Database-not-working-after-ASPNet-UpdatePanel-PostBack/Tue, 10 Jan 2017 08:20:09 GMTInsert data to Database not working after ASP.Net UpdatePanel PostBack<p>please you misunderstood my questio, i wanted to change your code from this</p> <p>&nbsp;</p> <pre class="brush: csharp">this.GetData(); } private void GetData() { SqlConnection con = new SqlConnection(str); SqlCommand cmd = new SqlCommand(&#34;SELECT UserName as Name,ContentPost as Title,Id,ImageName1 FROM USERPost1&#34;, con); SqlDataAdapter sda = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); sda.Fill(dt); GetMergedAll.DataSource = dt; GetMergedAll.DataBind(); }</pre> <p>to this</p> <p>&nbsp;</p> <p>&nbsp;</p> <pre class="brush: csharp"> this.GetData(); } private void GetData() { string str = ConfigurationManager.ConnectionStrings[&#34;conn&#34;].ConnectionString; string GetData = &#34;GetUserPOSTS&#34;; using (SqlConnection con = new SqlConnection(str)) { con.Open(); using (SqlCommand cmd = new SqlCommand(GetData, con)) { cmd.CommandType = CommandType.StoredProcedure; // cmd.Parameters.AddWithValue(&#34;@Name&#34;, Request.QueryString[&#34;Id&#34;].ToString()); cmd.Parameters.AddWithValue(&#34;@UserName&#34;, username); cmd.Parameters.AddWithValue(&#34;@Id&#34;, Id); SqlDataAdapter sda = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); sda.Fill(dt); GetMergedAll.DataSource = dt; GetMergedAll.DataBind(); } } } </pre> <p>but it didnt work</p>http://www.aspforums.net/Threads/105725/Insert-data-to-Database-not-working-after-ASPNet-UpdatePanel-PostBack/http://www.aspforums.net/Threads/105725/Insert-data-to-Database-not-working-after-ASPNet-UpdatePanel-PostBack/Tue, 10 Jan 2017 08:39:03 GMTInsert data to Database not working after ASP.Net UpdatePanel PostBack<p>i did it this way for procedure it worked</p> <p>&nbsp;</p> <pre class="brush: csharp"> this.GetData(); } private void GetData() { string str = ConfigurationManager.ConnectionStrings[&#34;conn&#34;].ConnectionString; string GetData = &#34;GetUserPOSTS&#34;; using (SqlConnection con = new SqlConnection(str)) { con.Open(); using (SqlCommand cmd = new SqlCommand(GetData, con)) { cmd.CommandType = CommandType.StoredProcedure; // cmd.Parameters.AddWithValue(&#34;@Name&#34;, Request.QueryString[&#34;Id&#34;].ToString()); cmd.Parameters.AddWithValue(&#34;@UserName&#34;, username); cmd.Parameters.AddWithValue(&#34;@Id&#34;, Id); SqlDataAdapter sda = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); sda.Fill(dt); GetMergedAll.DataSource = dt; GetMergedAll.DataBind(); } } } </pre> <p>&nbsp;</p>http://www.aspforums.net/Threads/105725/Insert-data-to-Database-not-working-after-ASPNet-UpdatePanel-PostBack/http://www.aspforums.net/Threads/105725/Insert-data-to-Database-not-working-after-ASPNet-UpdatePanel-PostBack/Tue, 10 Jan 2017 08:53:34 GMT