回发后丢失自定义参数. [英] Lost custom parameter after postback.
本文介绍了回发后丢失自定义参数.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使TreeNode重载以将参数添加到我的节点.我将此参数用作jquery选择器.
I try to overload TreeNode to add a parameter to my node. I use this parameter as jquery selector.
public class Node : TreeNode
{
public bool ContextMenu { get; set; }
protected override void RenderPreText(HtmlTextWriter writer)
{
base.RenderPreText(writer);
if (ContextMenu)
{
writer.AddAttribute("contextmenu","true");
}
}
}
生成页面时,参数在HTML中可见,但回发后会丢失.我试图重载LoadViewState和SaveViewState方法,但没有帮助.我该怎么办?
来自OP的更新程序:
呈现的HTML:
When the page is generated, parameter is visible in the HTML, but after postback it is lost. I tried to overload the LoadViewState and SaveViewState methods but it did not help. What I can do with this ?
UPDATER from OP:
rendered HTML:
<a contextmenu="true" class="MyTreeView_0" href="javascript:__doPostBack('MyTreeView','s1256\\1')" onclick="TreeView_SelectNode(MyTreeView_Data, this,'MyTreeViewt1');" id="MyTreeViewt1">node1</a>
回发后呈现HTML:
rendered HTML after postback:
<a class="MyTreeView_0" href="javascript:__doPostBack('MyTreeView','s1256\\1')" onclick="TreeView_SelectNode(MyTreeView_Data, this,'MyTreeViewt1');" id="MyTreeViewt1">node1</a>
推荐答案
通常的方法是将东西塞入您想要保留在会话变量内部的帽子,例如:Session["KeyName"] = theDataToKeepAround;
.通常,您希望将视图状态保持尽可能的浅.
TheDataToKeepAround可以是任何东西,包括DataSet,DataTable或自定义数据模型.
由于您使用的是jQuery,因此您可以考虑在浏览器中进行几乎所有操作,并使用 jQuery数据 [ ^ ]将数据附加到您的树-可能还有jQuery.getJSON [
The usual way is to stuff things that you want to keep around inside session variables like:Session["KeyName"] = theDataToKeepAround;
. You usually want to keep your viewstate as light as possible.
The theDataToKeepAround kan be just about anything, including a DataSet, DataTable, or a custom data model.
Since you are using jQuery, you could consider doing nearly everything in the browser, and use jQuery Data[^] to attach data to your tree - and possibly jQuery.getJSON[^] to get data from the server. If you move most of your processing to the browser you could avoid the whole issue.
Regards
Espen Harlinn
这篇关于回发后丢失自定义参数.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文