ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.[Solved] Request.Form with Master Page Error: Object reference not set to an instance of an object<p>Hi <a class="username" rel="nid@patel">nid@patel</a>,</p> <p>You can't access control value using Request.Form.GetValues("c_email") in master page, you need write like Request.Form.GetValues(c_email.UniqueID) to access value of control. Refer below sample.</p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <pre class="brush: html">&lt;%@ Page Title=&#34;&#34; Language=&#34;C#&#34; MasterPageFile=&#34;~/MasterPage.master&#34; AutoEventWireup=&#34;true&#34; CodeFile=&#34;Default.aspx.cs&#34; Inherits=&#34;_Default&#34; %&gt; &lt;asp:Content ID=&#34;Content1&#34; ContentPlaceHolderID=&#34;head&#34; runat=&#34;Server&#34;&gt; &lt;script type=&#34;text/javascript&#34;&gt; function addRow(tableID) { var table = document.getElementById(tableID); var rowCount = table.rows.length; var row = table.insertRow(rowCount); var colCount = table.rows[0].cells.length; for (var i = 0; i &lt; colCount; i++) { var newcell = row.insertCell(i); newcell.innerHTML = table.rows[0].cells[i].innerHTML; switch (newcell.childNodes[0].type) { case &#34;text&#34;: newcell.childNodes[0].value = &#34;&#34;; break; case &#34;checkbox&#34;: newcell.childNodes[0].checked = false; break; case &#34;select-one&#34;: newcell.childNodes[0].selectedIndex = 0; break; } } } function deleteRow(tableID) { try { var table = document.getElementById(tableID); var rowCount = table.rows.length; for (var i = 0; i &lt; rowCount; i++) { var row = table.rows[i]; var chkbox = row.cells[0].childNodes[1]; if (chkbox != null &amp;&amp; chkbox.checked == true) { if (rowCount &lt;= 1) { alert(&#34;Cannot delete all the rows.&#34;); break; } table.deleteRow(i); rowCount--; i--; } } } catch (e) { alert(e); } } &lt;/script&gt; &lt;/asp:Content&gt; &lt;asp:Content ID=&#34;Content2&#34; ContentPlaceHolderID=&#34;ContentPlaceHolder1&#34; runat=&#34;Server&#34;&gt; &lt;div class=&#34;container&#34;&gt; &lt;h2&gt; Sprinkler Irrigation Component&#39;s price &lt;small&gt;&lt;/small&gt; &lt;/h2&gt; &lt;ul class=&#34;responsive-table&#34;&gt; &lt;li class=&#34;table-row&#34;&gt; &lt;div class=&#34;col col-1&#34; data-label=&#34;Job Id&#34;&gt; Email:&lt;/div&gt; &lt;div class=&#34;col col-2&#34; data-label=&#34;Customer Name&#34;&gt; &lt;asp:TextBox CssClass=&#34;form-control&#34; ID=&#34;c_email&#34; placeholder=&#34;Email&#34; runat=&#34;server&#34;&gt;&lt;/asp:TextBox&gt; &lt;/div&gt; &lt;div class=&#34;col col-3&#34; data-label=&#34;Amount&#34;&gt; &lt;/div&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;div class=&#34;container&#34;&gt; &lt;ul class=&#34;responsive-table&#34;&gt; &lt;li class=&#34;table-row&#34;&gt; &lt;div class=&#34;col col-1&#34; data-label=&#34;Job Id&#34;&gt; Nozzle&lt;/div&gt; &lt;div class=&#34;col col-2&#34;&gt; &lt;table id=&#34;dataTable1&#34; class=&#34;table-bordered table-hover table-striped table&#34;&gt; &lt;tr&gt; &lt;td&gt; &lt;input type=&#34;checkbox&#34; name=&#34;chk&#34; /&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:TextBox ID=&#34;nozzle_lph&#34; runat=&#34;server&#34; type=&#34;text&#34; placeholder=&#34;LPH&#34;&gt;&lt;/asp:TextBox&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:TextBox ID=&#34;nozzle_price&#34; runat=&#34;server&#34; type=&#34;text&#34; placeholder=&#34;RS./unit&#34;&gt;&lt;/asp:TextBox&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/div&gt; &lt;div class=&#34;col col-3&#34;&gt; &lt;/div&gt; &lt;div class=&#34;col col-4&#34;&gt; &lt;input type=&#34;button&#34; class=&#34;btn btn-danger active&#34; value=&#34;Add Row&#34; onclick=&#34;addRow(&#39;dataTable1&#39;)&#34; /&gt;&lt;hr /&gt; &lt;input type=&#34;button&#34; class=&#34;btn btn-info active&#34; value=&#34;Delete Row&#34; onclick=&#34;deleteRow(&#39;dataTable1&#39;)&#34; /&gt; &lt;/div&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;div class=&#34;container&#34;&gt; &lt;ul class=&#34;responsive-table&#34;&gt; &lt;li class=&#34;table-row&#34;&gt; &lt;div class=&#34;col col-1&#34; data-label=&#34;Job Id&#34;&gt; Lateral&lt;/div&gt; &lt;div class=&#34;col col-2&#34;&gt; &lt;table id=&#34;dataTable2&#34; class=&#34;table-bordered table-hover table-striped table&#34;&gt; &lt;tr&gt; &lt;td&gt; &lt;input type=&#34;checkbox&#34; name=&#34;chk&#34; /&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:TextBox ID=&#34;txt_lat_mm&#34; runat=&#34;server&#34; type=&#34;text&#34; placeholder=&#34;LPH&#34;&gt;&lt;/asp:TextBox&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:TextBox ID=&#34;txt_lat_price&#34; runat=&#34;server&#34; type=&#34;text&#34; placeholder=&#34;RS./unit&#34;&gt;&lt;/asp:TextBox&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/div&gt; &lt;div class=&#34;col col-3&#34;&gt; &lt;/div&gt; &lt;div class=&#34;col col-4&#34;&gt; &lt;input type=&#34;button&#34; class=&#34;btn btn-danger active&#34; value=&#34;Add Row&#34; onclick=&#34;addRow(&#39;dataTable2&#39;)&#34; /&gt;&lt;hr /&gt; &lt;input type=&#34;button&#34; class=&#34;btn btn-info active&#34; value=&#34;Delete Row&#34; onclick=&#34;deleteRow(&#39;dataTable2&#39;)&#34; /&gt; &lt;/div&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;div class=&#34;container&#34;&gt; &lt;ul class=&#34;responsive-table&#34;&gt; &lt;li class=&#34;table-row&#34;&gt; &lt;div class=&#34;col col-1&#34; data-label=&#34;Job Id&#34;&gt; Submain Pipe&lt;/div&gt; &lt;div class=&#34;col col-2&#34;&gt; &lt;table id=&#34;dataTable3&#34; class=&#34;table-bordered table-hover table-striped table&#34;&gt; &lt;tr&gt; &lt;td&gt; &lt;input type=&#34;checkbox&#34; name=&#34;chk&#34; /&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:TextBox ID=&#34;txt_smain_mm&#34; runat=&#34;server&#34; type=&#34;text&#34; placeholder=&#34;LPH&#34;&gt;&lt;/asp:TextBox&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:TextBox ID=&#34;txt_smain_price&#34; runat=&#34;server&#34; type=&#34;text&#34; placeholder=&#34;RS./unit&#34;&gt;&lt;/asp:TextBox&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/div&gt; &lt;div class=&#34;col col-3&#34;&gt; &lt;/div&gt; &lt;div class=&#34;col col-4&#34;&gt; &lt;input type=&#34;button&#34; class=&#34;btn btn-danger active&#34; value=&#34;Add Row&#34; onclick=&#34;addRow(&#39;dataTable3&#39;)&#34; /&gt;&lt;hr /&gt; &lt;input type=&#34;button&#34; class=&#34;btn btn-info active&#34; value=&#34;Delete Row&#34; onclick=&#34;deleteRow(&#39;dataTable3&#39;)&#34; /&gt; &lt;/div&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;div class=&#34;container&#34;&gt; &lt;ul class=&#34;responsive-table&#34;&gt; &lt;li class=&#34;table-row&#34;&gt; &lt;div class=&#34;col col-1&#34; data-label=&#34;Job Id&#34;&gt; Main Pipe&lt;/div&gt; &lt;div class=&#34;col col-2&#34;&gt; &lt;table id=&#34;dataTable4&#34; class=&#34;table-bordered table-hover table-striped table&#34;&gt; &lt;tr&gt; &lt;td&gt; &lt;input type=&#34;checkbox&#34; name=&#34;chk&#34; /&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:TextBox ID=&#34;txt_main_mm&#34; runat=&#34;server&#34; type=&#34;text&#34; placeholder=&#34;LPH&#34;&gt;&lt;/asp:TextBox&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:TextBox ID=&#34;txt_main_price&#34; runat=&#34;server&#34; type=&#34;text&#34; placeholder=&#34;RS./unit&#34;&gt;&lt;/asp:TextBox&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/div&gt; &lt;div class=&#34;col col-3&#34;&gt; &lt;/div&gt; &lt;div class=&#34;col col-4&#34;&gt; &lt;input type=&#34;button&#34; class=&#34;btn btn-danger active&#34; value=&#34;Add Row&#34; onclick=&#34;addRow(&#39;dataTable4&#39;)&#34; /&gt;&lt;hr /&gt; &lt;input type=&#34;button&#34; class=&#34;btn btn-info active&#34; value=&#34;Delete Row&#34; onclick=&#34;deleteRow(&#39;dataTable4&#39;)&#34; /&gt; &lt;/div&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;div class=&#34;container&#34;&gt; &lt;ul class=&#34;responsive-table&#34;&gt; &lt;li class=&#34;table-row&#34;&gt; &lt;div class=&#34;col col-1&#34; data-label=&#34;Job Id&#34;&gt; Motor Pumping Unit&lt;/div&gt; &lt;div class=&#34;col col-2&#34;&gt; &lt;table id=&#34;dataTable5&#34; class=&#34;table-bordered table-hover table-striped table&#34;&gt; &lt;tr&gt; &lt;td&gt; &lt;input type=&#34;checkbox&#34; name=&#34;chk&#34; /&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:TextBox ID=&#34;txt_mpum_hp&#34; runat=&#34;server&#34; type=&#34;text&#34; placeholder=&#34;LPH&#34;&gt;&lt;/asp:TextBox&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:TextBox ID=&#34;txt_mpump_price&#34; runat=&#34;server&#34; type=&#34;text&#34; placeholder=&#34;RS./unit&#34;&gt;&lt;/asp:TextBox&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/div&gt; &lt;div class=&#34;col col-3&#34;&gt; &lt;/div&gt; &lt;div class=&#34;col col-4&#34;&gt; &lt;input type=&#34;button&#34; class=&#34;btn btn-danger active&#34; value=&#34;Add Row&#34; onclick=&#34;addRow(&#39;dataTable5&#39;)&#34; /&gt;&lt;hr /&gt; &lt;input type=&#34;button&#34; class=&#34;btn btn-info active&#34; value=&#34;Delete Row&#34; onclick=&#34;deleteRow(&#39;dataTable5&#39;)&#34; /&gt; &lt;/div&gt; &lt;/li&gt; &lt;li class=&#34;table-row&#34;&gt; &lt;div class=&#34;col col-1&#34; data-label=&#34;Job Id&#34;&gt; &lt;/div&gt; &lt;div class=&#34;col col-2&#34; data-label=&#34;Customer Name&#34;&gt; &lt;asp:Button ID=&#34;sprink_submit&#34; runat=&#34;server&#34; CssClass=&#34;btn btn-danger btn-group-lg active&#34; Text=&#34;Submit&#34; OnClick=&#34;sprink_submit_Click&#34; /&gt; &lt;/div&gt; &lt;div class=&#34;col col-3&#34; data-label=&#34;Amount&#34;&gt; &lt;asp:Button ID=&#34;Button2&#34; runat=&#34;server&#34; CssClass=&#34;btn btn-warning btn-group-lg active&#34; Text=&#34;Back&#34; /&gt; &lt;/div&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/asp:Content&gt; </pre> <p><span style="text-decoration: underline;"><strong>Namespaces</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System.Data.SqlClient; using System.Configuration;</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.Data.SqlClient Imports System.Configuration</pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected void sprink_submit_Click(object sender, EventArgs e) { string constr = ConfigurationManager.ConnectionStrings[&#34;Mycon&#34;].ConnectionString; SqlConnection con = new SqlConnection(constr); SqlCommand cmd = new SqlCommand(&#34;INSERT INTO company_sprinkler_data(company_email,nozzle_lph,nozzle_price,lateral_mm,lateral_price,main_mm,main_price,submain_mm,submain_price,Sp_mpump_hp,Sp_mpump_price)values(@company_email,@nozzle_lph,@nozzle_price,@lateral_mm,@lateral_price,@main_mm,@main_price,@submain_mm,@submain_price,@Sp_mpump_hp,@Sp_mpump_price)&#34;); string[] textboxValues1 = Request.Form.GetValues(c_email.UniqueID); string[] textboxValues2 = Request.Form.GetValues(nozzle_lph.UniqueID); string[] textboxValues3 = Request.Form.GetValues(nozzle_price.UniqueID); string[] textboxValues4 = Request.Form.GetValues(txt_lat_mm.UniqueID); string[] textboxValues5 = Request.Form.GetValues(txt_lat_price.UniqueID); string[] textboxValues6 = Request.Form.GetValues(txt_smain_mm.UniqueID); string[] textboxValues7 = Request.Form.GetValues(txt_smain_price.UniqueID); string[] textboxValues8 = Request.Form.GetValues(txt_main_mm.UniqueID); string[] textboxValues9 = Request.Form.GetValues(txt_main_price.UniqueID); string[] textboxValues10 = Request.Form.GetValues(txt_mpum_hp.UniqueID); string[] textboxValues11 = Request.Form.GetValues(txt_mpump_price.UniqueID); int length = 0; if (textboxValues2.Length &gt; length) { length = textboxValues2.Length; } else if (textboxValues3.Length &gt; length) { length = textboxValues3.Length; } else if (textboxValues4.Length &gt; length) { length = textboxValues4.Length; } else if (textboxValues5.Length &gt; length) { length = textboxValues5.Length; } else if (textboxValues6.Length &gt; length) { length = textboxValues6.Length; } else if (textboxValues7.Length &gt; length) { length = textboxValues7.Length; } else if (textboxValues8.Length &gt; length) { length = textboxValues8.Length; } else if (textboxValues9.Length &gt; length) { length = textboxValues9.Length; } else if (textboxValues10.Length &gt; length) { length = textboxValues10.Length; } else if (textboxValues11.Length &gt; length) { length = textboxValues11.Length; } for (int i = 0; i &lt; length; i++) { cmd = new SqlCommand(&#34;INSERT INTO company_sprinkler_data(company_email,nozzle_lph,nozzle_price,lateral_mm,lateral_price,main_mm,main_price,submain_mm,submain_price,Sp_mpump_hp,Sp_mpump_price)values(@company_email,@nozzle_lph,@nozzle_price,@lateral_mm,@lateral_price,@main_mm,@main_price,@submain_mm,@submain_price,@Sp_mpump_hp,@Sp_mpump_price)&#34;); cmd.Parameters.AddWithValue(&#34;@company_email&#34;, textboxValues1[0]); cmd.Parameters.AddWithValue(&#34;@nozzle_lph&#34;, textboxValues2.Length &gt; i ? textboxValues2[i] : &#34;&#34;); cmd.Parameters.AddWithValue(&#34;@nozzle_price&#34;, textboxValues3.Length &gt; i ? textboxValues3[i] : &#34;&#34;); cmd.Parameters.AddWithValue(&#34;@lateral_mm&#34;, textboxValues4.Length &gt; i ? textboxValues4[i] : &#34;&#34;); cmd.Parameters.AddWithValue(&#34;@lateral_price&#34;, textboxValues5.Length &gt; i ? textboxValues5[i] : &#34;&#34;); cmd.Parameters.AddWithValue(&#34;@main_mm&#34;, textboxValues6.Length &gt; i ? textboxValues6[i] : &#34;&#34;); cmd.Parameters.AddWithValue(&#34;@main_price&#34;, textboxValues7.Length &gt; i ? textboxValues7[i] : &#34;&#34;); cmd.Parameters.AddWithValue(&#34;@submain_mm&#34;, textboxValues8.Length &gt; i ? textboxValues8[i] : &#34;&#34;); cmd.Parameters.AddWithValue(&#34;@submain_price&#34;, textboxValues9.Length &gt; i ? textboxValues9[i] : &#34;&#34;); cmd.Parameters.AddWithValue(&#34;@Sp_mpump_hp&#34;, textboxValues10.Length &gt; i ? textboxValues10[i] : &#34;&#34;); cmd.Parameters.AddWithValue(&#34;@Sp_mpump_price&#34;, textboxValues11.Length &gt; i ? textboxValues11[i] : &#34;&#34;); con.Open(); cmd.ExecuteNonQuery(); con.Close(); c_email.Text = &#34; &#34;; } }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Protected Sub sprink_submit_Click(ByVal sender As Object, ByVal e As EventArgs) Dim constr As String = ConfigurationManager.ConnectionStrings(&#34;Mycon&#34;).ConnectionString Dim con As SqlConnection = New SqlConnection(constr) Dim cmd As SqlCommand = New SqlCommand(&#34;INSERT INTO company_sprinkler_data(company_email,nozzle_lph,nozzle_price,lateral_mm,lateral_price,main_mm,main_price,submain_mm,submain_price,Sp_mpump_hp,Sp_mpump_price)values(@company_email,@nozzle_lph,@nozzle_price,@lateral_mm,@lateral_price,@main_mm,@main_price,@submain_mm,@submain_price,@Sp_mpump_hp,@Sp_mpump_price)&#34;) Dim textboxValues1 As String() = Request.Form.GetValues(c_email.UniqueID) Dim textboxValues2 As String() = Request.Form.GetValues(nozzle_lph.UniqueID) Dim textboxValues3 As String() = Request.Form.GetValues(nozzle_price.UniqueID) Dim textboxValues4 As String() = Request.Form.GetValues(txt_lat_mm.UniqueID) Dim textboxValues5 As String() = Request.Form.GetValues(txt_lat_price.UniqueID) Dim textboxValues6 As String() = Request.Form.GetValues(txt_smain_mm.UniqueID) Dim textboxValues7 As String() = Request.Form.GetValues(txt_smain_price.UniqueID) Dim textboxValues8 As String() = Request.Form.GetValues(txt_main_mm.UniqueID) Dim textboxValues9 As String() = Request.Form.GetValues(txt_main_price.UniqueID) Dim textboxValues10 As String() = Request.Form.GetValues(txt_mpum_hp.UniqueID) Dim textboxValues11 As String() = Request.Form.GetValues(txt_mpump_price.UniqueID) Dim length As Integer = 0 If textboxValues2.Length &gt; length Then length = textboxValues2.Length ElseIf textboxValues3.Length &gt; length Then length = textboxValues3.Length ElseIf textboxValues4.Length &gt; length Then length = textboxValues4.Length ElseIf textboxValues5.Length &gt; length Then length = textboxValues5.Length ElseIf textboxValues6.Length &gt; length Then length = textboxValues6.Length ElseIf textboxValues7.Length &gt; length Then length = textboxValues7.Length ElseIf textboxValues8.Length &gt; length Then length = textboxValues8.Length ElseIf textboxValues9.Length &gt; length Then length = textboxValues9.Length ElseIf textboxValues10.Length &gt; length Then length = textboxValues10.Length ElseIf textboxValues11.Length &gt; length Then length = textboxValues11.Length End If For i As Integer = 0 To length - 1 cmd = New SqlCommand(&#34;INSERT INTO company_sprinkler_data(company_email,nozzle_lph,nozzle_price,lateral_mm,lateral_price,main_mm,main_price,submain_mm,submain_price,Sp_mpump_hp,Sp_mpump_price)values(@company_email,@nozzle_lph,@nozzle_price,@lateral_mm,@lateral_price,@main_mm,@main_price,@submain_mm,@submain_price,@Sp_mpump_hp,@Sp_mpump_price)&#34;) cmd.Parameters.AddWithValue(&#34;@company_email&#34;, textboxValues1(0)) cmd.Parameters.AddWithValue(&#34;@nozzle_lph&#34;, If(textboxValues2.Length &gt; i, textboxValues2(i), &#34;&#34;)) cmd.Parameters.AddWithValue(&#34;@nozzle_price&#34;, If(textboxValues3.Length &gt; i, textboxValues3(i), &#34;&#34;)) cmd.Parameters.AddWithValue(&#34;@lateral_mm&#34;, If(textboxValues4.Length &gt; i, textboxValues4(i), &#34;&#34;)) cmd.Parameters.AddWithValue(&#34;@lateral_price&#34;, If(textboxValues5.Length &gt; i, textboxValues5(i), &#34;&#34;)) cmd.Parameters.AddWithValue(&#34;@main_mm&#34;, If(textboxValues6.Length &gt; i, textboxValues6(i), &#34;&#34;)) cmd.Parameters.AddWithValue(&#34;@main_price&#34;, If(textboxValues7.Length &gt; i, textboxValues7(i), &#34;&#34;)) cmd.Parameters.AddWithValue(&#34;@submain_mm&#34;, If(textboxValues8.Length &gt; i, textboxValues8(i), &#34;&#34;)) cmd.Parameters.AddWithValue(&#34;@submain_price&#34;, If(textboxValues9.Length &gt; i, textboxValues9(i), &#34;&#34;)) cmd.Parameters.AddWithValue(&#34;@Sp_mpump_hp&#34;, If(textboxValues10.Length &gt; i, textboxValues10(i), &#34;&#34;)) cmd.Parameters.AddWithValue(&#34;@Sp_mpump_price&#34;, If(textboxValues11.Length &gt; i, textboxValues11(i), &#34;&#34;)) con.Open() cmd.ExecuteNonQuery() con.Close() c_email.Text = &#34; &#34; Next End Sub</pre> <p>&nbsp;</p> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/147967/Solved-RequestForm-with-Master-Page-Error-Object-reference-not-set-to-an-instance-of-an-object/https://www.aspforums.net:443/Threads/147967/Solved-RequestForm-with-Master-Page-Error-Object-reference-not-set-to-an-instance-of-an-object/Wed, 07 Aug 2019 06:17:06 GMT