开发者

Getting text out of textarea from a ASP.NET GridView update

开发者 https://www.devze.com 2023-02-07 05:01 出处:网络
i\'m loosing my mind. Using ASP.NET in a GridView, amongst other controls, I have the following: <asp:TemplateField HeaderText=\"Intention\">

i'm loosing my mind. Using ASP.NET in a GridView, amongst other controls, I have the following:

<asp:TemplateField HeaderText="Intention">
    <EditItemTemplate>
        <asp:TextBox ID="IntentionInfo" Enabled="true" TextMode="MultiLine" Wrap="true" runat="server" />
    </EditItemTemplate>
    <ItemTemplate>
        <asp:TextBox ID="IntentionInfo" Enabled="false" TextMode="MultiLine" runat="server" />
    </ItemTemplate>
</asp:TemplateField>

I would like to take the value out of this textarea and save in a database. How开发者_Go百科ever, server side, I try to pull the value out, like such:

string txt = (TextBox)DonationResultsTable.Rows[e.RowIndex].Cells[6].Controls[1].Text;

... but I keep getting the value that was SENT to the Client.

I wrote this javascript and I can see the values change in the DOM, but still the server keeps taking the old value.

$("textarea").change(function()
{
    var txt = $(this).val();

    $(this).html(txt).text(txt);
});

So my guess was ViewState, but I disabled it for those controls, like this:

<asp:TextBox ID="IntentionInfo" ViewStateMode="Disabled" Enabled="false" TextMode="MultiLine" runat="server" />

Still nothing! Any ideas?


One option could be to use a hidden field and update it on text changed for the text area. You could do this with jQuery like this:

$("textarea[id$=tbTest]").change(function () {
                $("input[id$=hdnVal]").val($("textarea[id$=tbTest]").val());
            });

Then on the server side, you can retrieve the hidden field's value and save it to your database.

0

精彩评论

暂无评论...
验证码 换一张
取 消