asp.net : Get the value from textarea

匿名 (未验证) 提交于 2019-12-03 01:20:02

问题:

i am creating one form for image upload drag and drop through jquery.

when i dragged one image to aspx form, that time that image preview and title ( textarea ) and desc ( textarea ) created to aspx page.

after entered the title and desc, it is saved to database when i click save button.

i couldn't get the textarea control in c# (code behind ) ?

textarea does not added directly to aspx page. it is is dynamically added through jquery so????

in jquery textarea added

<textarea id="txtImagename1" runat="server" rows="1" cols="50"></textarea>

code behind

HtmlTextArea txtImageupload = (HtmlTextArea)(frm.FindControl("txtImagename1")); string imagename = txtImageupload.Value;

回答1:

Try

Request.Form["txtImagename1"]

No need of runat="server"

Also, add name="txtImagename1"

<textarea id="txtImagename1" name="txtImagename1" rows="1" cols="50"></textarea>


回答2:

Add name attribute to the Dynamic control :

 <textarea id="txtImagename1" name="txtImagename1" runat="server" rows="1" cols="50">  </textarea>

from your codebehind :

Request.Form["txtImagename1"]


回答3:

TextBox txtImageName = (TextBox)Page.FindControl("txtImagename1"); string strFromTextArea = txtImageName.Text;

Note :

  • "Page" should be container of your textarea control. If your textarea is in panel, use your panel object instead of Page.
  • Multiple lines textbox control is textarea in HTML control.


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!