How to access the TextArea value from a content page

I have a TextArea control in my content page which is inside an UpdatePanel:

<asp:UpdatePanel runat="server" ClientIDMode="Static" ID="upTaskDetailRight" UpdateMode="Conditional">
    <ContentTemplate>
        <div style="width: 98%; padding-bottom: 10px;" class="brClear">
            <div style="width: 98%; height: 120px;">
                <textarea id="taskNotes" runat="server" class="taskNotes" style="width: 100%; height: 100%; scrollbar-base-color: #A0A0A0; scrollbar-base-color: #A0A0A0; scrollbar-3dlight-color: #A0A0A0; scrollbar-highlight-color: #A0A0A0; scrollbar-track-color: #EBEBEB; scrollbar-arrow-color: #FFFFFF; scrollbar-shadow-color: #A0A0A0; scrollbar-darkshadow-color: #A0A0A0;"></textarea>
            </div>
        </div>
    </ContentTemplate>
</asp:UpdatePanel>

I have a button in my MasterPage which is accessing the TextArea value from the content page and updating the SQL Database:

<asp:Panel ID="Panel93" runat="server" CssClass="navInnerDivContentsTopSubTwo">
    <asp:ImageButton ID="ibSave" ImageUrl="~/theImages/Save.png" runat="server" CssClass="navImages" OnClick="btnSave_Click" />
    <br />
    <asp:LinkButton ID="btnSave" runat="server" Text="Save" ClientIDMode="Static" OnClick="btnSave_Click" CssClass="linkOff" />
</asp:Panel>

Code-behind:

System.Web.UI.HtmlControls.HtmlTextArea lblTDNotes;
lblTDNotes = (System.Web.UI.HtmlControls.HtmlTextArea)ContentMain.FindControl("taskNotes");
protected void btnSave_Click(object sender, EventArgs e)
{
    string strSaveQuery = @"UPDATE HSI.RMMEMO SET MEMO = '" + lblTDNotes.Value + "' WHERE MEMOID = '" + hfMemoIDYT.Value  + "'";
    //MessageBox.Show(strSaveQuery);

    using (SqlConnection scConn = new SqlConnection(strMainConn))
    {
        try
        {
            scConn.Open();
            SqlCommand cmd = new SqlCommand(strSaveQuery, scConn);

            cmd.ExecuteNonQuery();

            Response.Redirect("YourTasks.aspx");
        }
        catch (Exception ce)
        {
        }
    }
}

When the page loads, the TextArea has some pre populated data. If I make any changes to the TextArea data (add or remove text) and hit the SAVE button in the Master page, the lblTDNoted.Value from the strSaveQuery is using the pre populated data and not the updated entry.

How do I get the updated entry from the textarea?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Add <triggers> to your UpdatePanel.

<asp:UpdatePanel runat="server" ...>
    <ContentTemplate>
        ...
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="btnSave" EventName="Click" />
    </Triggers>
</asp:UpdatePanel>


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x