开发者

How to get content from an editable div tag in asp.net?

After edit the content in frontend, how can I get the co开发者_运维问答ntent in backend? asdf.InnerHtml does not work, I mean it won't return new content that I entered in but just what it has on page first load. I need html content of that div.


The best way to do something like this is to use javascript to place the content into a hidden text box.

Once the page has posted back, this value is available on the server.

So you want to place one of these on your page, which you can manipulate however you want client side, and it will be submitted to the server when posted back.

It would look something like (on the client):

HTML:

<input type="hidden" name="html" value="">

Javascript:

 getElementById('<%=hidden.ClientID%>').value = asdf.InnerHtml

Then check the value server side.


I am not positive this will work but what if you gave the div a name attribute . Then in the backend you might be able to get the contents with Request["someName"].

If not, you could definately put a runat="server" hidden html input element in the page and after the edit use javascript to place the contents of the div into the value of the hidden input.


The value should be being posted to the server assuming you have run="server" on the div element.

You can make a quick hack on the server side page load to set the InnerHTML of your div.

if(Request.Params(myDiv.ClientID) != null)
    myDiv.InnerHtml = Request.Params(myDiv.ClientID);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜