How to append text value of a label control with textbox control. How to insert this value into database?

StackOverflow https://stackoverflow.com/questions/22759322

  •  24-06-2023
  •  | 
  •  

Frage

I have a web form in which I am using a textbox control with multiline property and below this control I am using a label control. I want that whatever I type in my textbox after every entry the text in label control gets appended with the text I have given as input. This is my aspx page-

<table border="1">
    <tr>
        <td>Content:</td>
        <td>
            <asp:TextBox ID="txtdetails" runat="server" TextMode="MultiLine" Height="101px" Width="328px"></asp:TextBox><br />
            <asp:Label ID="lblsource" runat="server" Text=""></asp:Label>
        </td>
    </tr>
    <tr>
        <td colspan="2" align="center">
            <asp:Button ID="btnsub" runat="server" Text="Submit" onclick="btnsub_Click" />
        </td>
    </tr>
</table>

This is my cs page-

protected void btnsub_Click(object sender, EventArgs e)
{
    try
    {
        if (txtdetails.Text != "")
        {
            txtdetails.Text = txtdetails.Text.Replace(System.Environment.NewLine, "<br>");
            maxid = g1.generate_max_reg_id("select max(id) from tbl_content");
            rows = g1.ExecDB("insert into tbl_content values(" + maxid + ",'" + txtdetails.Text.ToString() + string.Format("{0}<strong>MyName</strong>", lblsource.Text)+"')");
            txtdetails.Text = string.Empty;
         }
         if (rows > 0)
         {
             ClientScript.RegisterStartupScript(typeof(Page), "AlertMessage", "alert('Successful!!!');window.location='textare_append.aspx';", true);
         }
     }
     catch (Exception ex)
     {
         Response.Write(ex.ToString());
     }
 }

I am getting a SQL exception in insert query. Please guide where I am doing wrong?

War es hilfreich?

Lösung

protected void btnsub_Click(object sender, EventArgs e)
{
    try
    {
        if (txtdetails.Text != "")
        {
            lblsource.Text=lblsource.Text+ txtdetails.Text;
            txtdetails.Text = txtdetails.Text.Replace(System.Environment.NewLine, "<br>");
            maxid = g1.generate_max_reg_id("select max(id) from tbl_content");
            rows = g1.ExecDB("insert into tbl_content values(" + maxid + ",'" + txtdetails.Text.ToString() + string.Format("{0}<strong>MyName</strong>", lblsource.Text)+"')");
            txtdetails.Text = string.Empty;
         }
         if (rows > 0)
         {
             ClientScript.RegisterStartupScript(typeof(Page), "AlertMessage", "alert('Successful!!!');window.location='textare_append.aspx';", true);
         }
     }
     catch (Exception ex)
     {
         Response.Write(ex.ToString());
     }
 }
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top