Chetan Sarode Chetan Sarode - 4 months ago 5
Ajax Question

Load data from database in textbox

<div id="dialogEdit" style="display:none">
<label class="lab">Search Customer:-</label><asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
&nbsp;&nbsp;
<asp:Button ID="Button3" runat="server" Text="Search" OnClick="Button3_Click" />
<table>
<tbody>
<tr>
<td style="width:18%">
<label class="lab">Customer Name</label>
</td>
<td colspan="5" style="width:20%">
<asp:TextBox ID="CustomerName" runat="server" class="inp" style="font-size:12px" ></asp:TextBox>
</td>
<td style="width:15%" >

</td>
<td colspan="5" class="auto-style3">

</td>
<td style="width:15%">
<label class="lab">Mailing Name</label>
</td>
<td colspan="5" style="width:20%">
<asp:TextBox ID="MailingName" runat="server" class="inp" style="font-size:12px"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width:18%">
<label class="lab">Address Line 1</label>
</td>
<td colspan="5" style="width:20%">
<asp:TextBox ID="Address" runat="server" class="inp" style="font-size:12px"></asp:TextBox>
</td>
<td style="width:15%">
<label class="lab">Address Line 2</label>
</td>
<td colspan="5" class="auto-style3">
<asp:TextBox ID="Address1" runat="server" class="inp" style="font-size:12px"></asp:TextBox>
</td>
<td style="width:15%">
<label class="lab">Address Line 3</label>
</td>
<td colspan="5" style="width:20%">
<asp:TextBox ID="Address2" runat="server" class="inp" style="font-size:12px"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width:18%">
<label class="lab">City</label>
</td>
<td colspan="5" style="width:20%">
<asp:TextBox ID="City" runat="server" class="inp" style="font-size:12px"></asp:TextBox>
</td>
<td style="width:15%">
<label class="lab">Zip Code</label>
</td>
<td colspan="5" class="auto-style3">
<asp:TextBox ID="PinCode" runat="server" class="inp" style="font-size:12px"></asp:TextBox>
</td>
<td style="width:15%">
<label class="lab">State</label>
</td>
<td colspan="5" style="width:20%">
<asp:TextBox ID="State" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width:18%">
<label class="lab">Country</label>
</td>
<td colspan="5" style="width:20%">
<asp:TextBox ID="Country" runat="server"></asp:TextBox>
</td>
<td style="width:15%" >
&nbsp;</td>
<td colspan="5" class="auto-style3">
&nbsp;</td>
<td style="width:15%" >
&nbsp;</td>
<td colspan="5" style="width:20%">

</td>
</tr>
<tr>
<td style="width:18%">

</td>
<td colspan="5" style="width:20%">

</td>
<td style="width:15%">

</td>
<td colspan="5" class="auto-style3">

</td>
<td style="width:15%">

</td>
<td colspan="5" style="width:20%">

</td>
</tr>


</tbody>

</table>
<table>
<tbody>

<tr>
<td style="width:18%">
<label class="lab">Address Line 1</label>
</td>
<td colspan="5" style="width:20%">
<asp:TextBox ID="M2Address1" runat="server" class="inp" style="font-size:12px"></asp:TextBox>
</td>
<td style="width:15%">
<label class="lab">Address Line 2</label>
</td>
<td colspan="5" style="width:20%">
<asp:TextBox ID="M2Address2" runat="server" class="inp" style="font-size:12px"></asp:TextBox>
</td>
<td style="width:15%">
<label class="lab">Address Line 3</label>
</td>
<td colspan="5" style="width:20%">
<asp:TextBox ID="M2Address3" runat="server" class="inp" style="font-size:12px"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width:18%">
<label class="lab">City</label>
</td>
<td colspan="5" style="width:20%">
<asp:TextBox ID="M2City" runat="server" class="inp" style="font-size:12px"></asp:TextBox>
</td>
<td style="width:15%">
<label class="lab">Zip Code</label>
</td>
<td colspan="5" style="width:20%">
<asp:TextBox ID="M2PinCode" runat="server" class="inp" style="font-size:12px"></asp:TextBox>
</td>
<td style="width:15%">
<label class="lab">State</label>
</td>
<td colspan="5" style="width:20%">
<asp:TextBox ID="State1" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width:18%">
<label class="lab">Country</label>
</td>
<td colspan="5" style="width:20%">
<asp:TextBox ID="Country1" runat="server"></asp:TextBox>
</td>
<td style="width:15%" >

</td>
<td colspan="5" style="width:20%">


</td>
<td style="width:15%" >

</td>
<td colspan="5" style="width:20%">

</td>

</tr>


</tbody>
</table>
<table>
<tbody>
<tr>
<td style="width:18%">
<label class="lab">Address Line 1</label>
</td>
<td colspan="5" style="width:20%">
<asp:TextBox ID="M3Address1" runat="server" class="inp" style="font-size:12px"></asp:TextBox>
</td>
<td style="width:15%">
<label class="lab">Address Line 2</label>
</td>
<td colspan="5" style="width:20%">
<asp:TextBox ID="M3Address2" runat="server" class="inp" style="font-size:12px"></asp:TextBox>
</td>
<td style="width:15%">
<label class="lab">Address Line 3</label>
</td>
<td colspan="5" style="width:20%">
<asp:TextBox ID="M3Address3" runat="server" class="inp" style="font-size:12px"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width:18%">
<label class="lab">City</label>
</td>
<td colspan="5" style="width:20%">
<asp:TextBox ID="M3City" runat="server" class="inp" style="font-size:12px"></asp:TextBox>
</td>
<td style="width:15%">
<label class="lab">Zip Code</label>
</td>
<td colspan="5" style="width:20%">
<asp:TextBox ID="M3PinCode" runat="server" class="inp" style="font-size:12px"></asp:TextBox>
</td>
<td style="width:15%">
<label class="lab">State</label>
</td>
<td colspan="5" style="width:20%">
<asp:TextBox ID="State3" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width:18%">
<label class="lab">Country</label>
</td>
<td colspan="5" style="width:20%">
<asp:TextBox ID="Country3" runat="server" Width="205px"></asp:TextBox>
</td>
<td style="width:15%" >

</td>
<td colspan="5" style="width:20%">


</td>
<td style="width:15%" >

</td>
<td colspan="5" style="width:20%">

</td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td style="width:18%">
<label class="lab">Telephone No</label>
</td>
<td colspan="5" style="width:20%">
<asp:TextBox ID="Telephone" runat="server" class="inp" style="font-size:12px"></asp:TextBox>
</td>
<td style="width:15%">
<label class="lab">Fax No</label>
</td>
<td colspan="5" style="width:20%">
<asp:TextBox ID="FaxNo" runat="server" class="inp" style="font-size:12px"></asp:TextBox>
</td>
<td style="width:15%">
<label class="lab">Mobile No</label>
</td>
<td colspan="5" style="width:20%">
<asp:TextBox ID="Mobile" runat="server" class="inp" style="font-size:12px"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width:18%">
<label class="lab">Email - Accounts</label>
</td>
<td colspan="5" style="width:20%">
<asp:TextBox ID="EmailAcc" runat="server" class="inp" style="font-size:12px"></asp:TextBox>

</td>
<td style="width:15%">
<label class="lab">Email - DSR</label>
</td>
<td colspan="5" style="width:20%">
<asp:TextBox ID="EmailDSR" runat="server" class="inp" style="font-size:12px"></asp:TextBox>
</td>
<td style="width:15%">
<label class="lab">Contact Person</label>
</td>
<td colspan="5" style="width:20%">
<asp:TextBox ID="ContPer" runat="server" class="inp" style="font-size:12px"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width:18%">
<label class="lab">STD Code</label>
</td>
<td colspan="5" style="width:20%">
<asp:TextBox ID="StdCode" runat="server" class="inp" style="font-size:12px"></asp:TextBox>
</td>
<td style="width:15%">
<label class="lab">ISD Code</label>
</td>
<td colspan="5" style="width:20%">
<asp:TextBox ID="ISDCODE" runat="server" class="inp" style="font-size:12px"></asp:TextBox>
</td>

</tr>
</tbody>

</table>
<table>
<tbody>
<tr>
<td style="width:18%">
<label class="lab">PAN No</label>
</td>
<td colspan="5" style="width:20%">
<asp:TextBox ID="PanNO" runat="server" class="inp" style="font-size:12px"></asp:TextBox>
</td>
<td style="width:15%">
<label class="lab">S.T. No</label>
</td>
<td colspan="5" style="width:20%">
<asp:TextBox ID="STNO" runat="server" class="inp" style="font-size:12px"></asp:TextBox>
</td>
<td style="width:15%">
<label class="lab">CST TIN No</label>
</td>
<td colspan="5" style="width:20%">
<asp:TextBox ID="CSTTIN" runat="server" class="inp" style="font-size:12px"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width:18%">
<label class="lab">VAT TIN No</label>
</td>
<td colspan="5" style="width:20%">
<asp:TextBox ID="VATTIN" runat="server" class="inp" style="font-size:12px"></asp:TextBox>

</td>
<td style="width:15%">
<label class="lab">Licence No</label>
</td>
<td colspan="5" style="width:20%">
<asp:TextBox ID="LICENCENO" runat="server" class="inp" style="font-size:12px"></asp:TextBox>

</td>

</tr>
</tbody>

</table>
<table>
<tbody>
<tr>
<td class="auto-style1">
<label class="lab">Ledger Name</label>
</td>
<td colspan="5" style="width:20%">
<asp:TextBox ID="TextBox18" runat="server" class="inp" style="font-size:12px" ></asp:TextBox>
</td>
<td style="width:15%">
<label class="lab">Group Under</label>
</td>
<td colspan="5" style="width:20%">
<asp:TextBox ID="tallygroup" runat="server"></asp:TextBox>
</td>
<td style="width:15%">
<label class="lab"></label>
</td>
<td colspan="5" style="width:20%">

</td>
</tr>
<tr>
<td class="auto-style1">
&nbsp;</td>
<td colspan="5" style="width:20%">
&nbsp;</td>
<td style="width:15%">
<label class="lab"></label>
</td>
<td colspan="5" style="width:20%">


</td>

</tr>
</tbody>

</table>
<table>
<tbody>
<tr>
<td style="width:13%">
<label class="lab">Sales Person Name</label>
</td>
<td colspan="5" style="width:10%">
<asp:TextBox ID="Salesperson" runat="server"></asp:TextBox>
</td>
<td style="width:14%">
<label class="lab">Customer Handled By</label>
</td>
<td colspan="5" style="width:20%">
<asp:TextBox ID="CustHandledBy" runat="server"></asp:TextBox>
</td>
<td>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</td>
</tr>
</tbody>

</table>
<br />
<asp:Button ID="Button4" runat="server" OnClick="Button4_Click" Text="Button" />
</div>


i have this textboxes in dialog box.i need search the customer code on first text box on search button click the data relented to that code is display in that textboxes then we edit it and save to database. originally the main problem is when i am enter the code and click on search button the page is refresh and dialog box is closed i need to search the data without the page refreshing.
ex-plane with one example.

Answer

Just put your control like textbox etc, under Update Panel below like example: <asp:UpdatePanel> <ContentTemplate> <table> <tbody> <tr> <td style="width:18%"> <label class="lab">Customer Name</label> </td> <td colspan="5" style="width:20%">
<asp:TextBox ID="CustomerName" runat="server" class="inp" style="font-size:12px" ></asp:TextBox> </td></td></tr> </tbody></table> </ContentTemplate> </asp:UpdatePanel>

in Code .cs file on button click event bind get value from database using command then inserted get value from database into textbox text like below example

Protected void Button3_Click (object sender, EventArgs e) { string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString; using (SqlConnection con = new SqlConnection { using (SqlCommand cmd = new SqlCommand("SELECT * FROM tablename where +"+TextBox2.text+" condition")) { using (SqlDataAdapter sda = new SqlDataAdapter()) { DataTable dt = new DataTable(); cmd.CommandType = CommandType.Text; cmd.Connection = con; sda.SelectCommand = cmd;
sda.Fill(dt); foreach (DataRow dtRow in dt.Rows) { // On all tables' columns foreach(DataRow row in dt.Rows) { TextBox1.Text = row["FirstName"].ToString(); TextBox2.Text = row["lastName"].ToString(); ...... etc } } } } }`

Comments