试过用复合控件包含treeview控件,但是失败,这次在右键菜单调用tree的回发js成功可以在页面后台绑定被编辑的节点,后台3个函数都可以编辑用c#传的参数e.mynode就是右键菜单的选中的节点
usingSystem;ponentModel;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Web;usingSystem.Text;usingSystem.Drawing.Design;usingSystem.IO;namespaceServerControl1{[Serializable]publicclassTreeViewc:TreeView{publicTreeViewc(){}[Bindable(true)][Category("搜索")][Description("资源(image/css/js)的客户端根目录")]publicstringClientScriptPath{get{Strings=(String)ViewState["ClientScriptPath"];return((s==null)?String.Empty:s);}set{ViewState["ClientScriptPath"]=value;}}protectedoverridevoidRaisePostBackEvent(stringeventArgument){base.RaisePostBackEvent(eventArgument);TreeNodetnNode=newTreeNode();//base.RaisePostBackEvent(eventArgument);stringsa=eventArgument.ToString();/*for(inti=0;i<this.Nodes.Count;i++){if(this.Nodes[i].Value==sa.Substring(sa.IndexOf('=')+1)){tnNode=this.Nodes[i];}}*/stringdf=sa.Substring(sa.IndexOf('=')+1).Replace("\\","/");tnNode=this.FindNode(df);//tnNode.ChildNodes.Clear();if(sa.StartsWith("copy")){Oncopynode(newnodeEventArgs(tnNode));}if(sa.StartsWith("paste")){Onpastenode(newnodeEventArgs(tnNode));}if(sa.StartsWith("cut")){Oncutnode(newnodeEventArgs(tnNode));}if(sa.StartsWith("delete")){Ondeleteenode(newnodeEventArgs(tnNode));}}publiceventEventHandlercopynode;protectedvirtualvoidOncopynode(EventArgse){if(copynode!=null){copynode(this,e);//Page.ClientScript.RegisterClientScriptBlock(Page.GetType(),"","<scriptlanguage='javascript'>alert('dfsd');</script>");}}publiceventEventHandlerpastenode;protectedvirtualvoidOnpastenode(EventArgse){if(pastenode!=null){pastenode(this,e);//Page.ClientScript.RegisterClientScriptBlock(Page.GetType(),"","<scriptlanguage='javascript'>alert('dfsd');</script>");}}publiceventEventHandleraddnode;protectedvirtualvoidOnaddnode(EventArgse){if(addnode!=null){addnode(this,e);//Page.ClientScript.RegisterClientScriptBlock(Page.GetType(),"","<scriptlanguage='javascript'>alert('dfsd');</script>");}}publiceventEventHandlerdeleteenode;protectedvirtualvoidOndeleteenode(EventArgse){if(deleteenode!=null){deleteenode(this,e);//Page.ClientScript.RegisterClientScriptBlock(Page.GetType(),"","<scriptlanguage='javascript'>alert('dfsd');</script>");}}publiceventEventHandlercutnode;protectedvirtualvoidOncutnode(EventArgse){if(cutnode!=null){cutnode(this,e);//Page.ClientScript.RegisterClientScriptBlock(Page.GetType(),"","<scriptlanguage='javascript'>alert('dfsd');</script>");}}/*protectedoverridevoidRenderContents(HtmlTextWriteroutput){output.Write("控件属性示例,请从:设计器界面<=>代码视图界面切换查看效果.");}*/protectedoverridevoidRender(HtmlTextWriteroutput){base.Render(output);//this.RenderControl(output);output.AddAttribute(HtmlTextWriterAttribute.Id,"myMenu");output.AddAttribute(HtmlTextWriterAttribute.Class,"contextMenu");output.RenderBeginTag(HtmlTextWriterTag.Ul);output.AddAttribute(HtmlTextWriterAttribute.Class,"copy");output.RenderBeginTag(HtmlTextWriterTag.Li);stringhref2=Page.ClientScript.GetPostBackClientHyperlink(this,"this.svr").Replace("'this.svr'","this.svr");output.AddAttribute(HtmlTextWriterAttribute.Href,href2);output.RenderBeginTag(HtmlTextWriterTag.A);//output.Write("<ahref=javascript:PostBackFromClient_"+this.ClientID+"();>editos</a>");output.Write("复制");output.RenderEndTag();output.RenderEndTag();output.AddAttribute(HtmlTextWriterAttribute.Class,"cut");output.RenderBeginTag(HtmlTextWriterTag.Li);stringhref23=Page.ClientScript.GetPostBackClientHyperlink(this,"this.svr").Replace("'this.svr'","this.svr");output.AddAttribute(HtmlTextWriterAttribute.Href,href23);output.RenderBeginTag(HtmlTextWriterTag.A);//output.Write("<ahref=javascript:PostBackFromClient_"+this.ClientID+"();>editos</a>");output.Write("剪切");output.RenderEndTag();output.RenderEndTag();output.AddAttribute(HtmlTextWriterAttribute.Class,"paste");output.RenderBeginTag(HtmlTextWriterTag.Li);stringhref233=Page.ClientScript.GetPostBackClientHyperlink(this,"this.svr").Replace("'this.svr'","this.svr");output.AddAttribute(HtmlTextWriterAttribute.Href,href233);output.RenderBeginTag(HtmlTextWriterTag.A);//output.Write("<ahref=javascript:PostBackFromClient_"+this.ClientID+"();>editos</a>");output.Write("粘贴");output.RenderEndTag();output.RenderEndTag();output.AddAttribute(HtmlTextWriterAttribute.Class,"delete");output.RenderBeginTag(HtmlTextWriterTag.Li);stringhref=Page.ClientScript.GetPostBackClientHyperlink(this,"this.svr").Replace("'this.svr'","this.svr");output.AddAttribute(HtmlTextWriterAttribute.Href,href);output.RenderBeginTag(HtmlTextWriterTag.A);//output.Write("<ahref=javascript:PostBackFromClient_"+this.ClientID+"();>editos</a>");output.Write("删除");output.RenderEndTag();output.RenderEndTag();output.AddAttribute(HtmlTextWriterAttribute.Class,"quit");output.RenderBeginTag(HtmlTextWriterTag.Li);//stringhref3="javascript:$('myMenu').hide()";//output.AddAttribute(HtmlTextWriterAttribute.Href,href3);//output.RenderBeginTag(HtmlTextWriterTag.A);output.Write("<ahref=\"javascript:a()\">取消</a>");//output.Write("新建");//output.RenderEndTag();output.RenderEndTag();output.RenderEndTag();/*output.Write("控件属性示例,请从:设计器界面<=>代码视图界面切换查看效果.");*/}protectedoverridevoidOnPreRender(EventArgse){stringstrJSPath=base.ResolveUrl(bine(this.ClientScriptPath,@"treejb.js"));if(!Page.ClientScript.IsClientScriptBlockRegistered(this.GetType(),"treejb")){Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"treejb","<scripttype='text/javascript'src='"+strJSPath+"'></script>",false);}base.OnPreRender(e);}}}
publicstaticTreeNodeStaTreeNode=newTreeNode();
protectedvoidTreecnt1_TextChanged1(objectsender,EventArgse){this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"Prompt","<scriptlanguage='javascript'>alert('oe');</script>");}protectedvoidTreeViewc1_copynode(objectsender,EventArgse){StaTreeNode=newTreeNode((easnodeEventArgs).MyNode.Text,(easnodeEventArgs).MyNode.Value);//StaTreeNode.ChildNodes.Clear();//ViewState["tno"]=(easnodeEventArgs).MyNode;strings=(easnodeEventArgs).MyNode.Value.ToString();stringb=s;/*this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"Prompt","<scriptlanguage='javascript'>alert('"+b+"');</script>");*/}protectedvoidTreeViewc1_SelectedNodeChanged(objectsender,EventArgse){TreeViewn=senderasTreeView;stringsd=n.Nodes.Count.ToString();//inta=0;}protectedvoidTreeViewc1_pastenode(objectsender,EventArgse){TreeNodetyh=(easnodeEventArgs).MyNode;tyh.ChildNodes.Add(StaTreeNode);strings=(easnodeEventArgs).MyNode.Value.ToString();stringb=s;/*this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"Prompt","<scriptlanguage='javascript'>alert('"+b+"');</script>");*/}protectedvoidTreeViewc1_cutnode(objectsender,EventArgse){StaTreeNode=(easnodeEventArgs).MyNode;StaTreeNode.Parent.ChildNodes.Remove(StaTreeNode);}protectedvoidTreeViewc1_deleteenode(objectsender,EventArgse){(easnodeEventArgs).MyNode.Parent.ChildNodes.Remove((easnodeEventArgs).MyNode);}//inta=0;
varsvr;functiona(){/*alert(ev.pageX);alert('aa')*/$("#myMenu").css({"display":"none"})}$(document).ready(function(){//alert($("#myMenu"))varf=$("#TreeViewc1").find("a");//alert(m.length);//varf=m.filter("a");//alert(f.length);for(vari=0;i<f.length;i++){//alert(f[i].id)f[i].oncontextmenu=function(ev){//alert(ev.pageX);//svr=ev.currentTarget.innerHTML;svr=ev.currentTarget.href;//alert(svr);/*$("#myMenu").style.display="block";$("#myMenu").style.left=ev.pageX;$("#myMenu").style.top=ev.pageY;*/$("#myMenu").css({"display":"block","left":ev.pageX,"top":ev.pageY})$(".copy").children("a").attr("href",svr.replace(",'s",",'copy="));$(".cut").children("a").attr("href",svr.replace(",'s",",'cut="));$(".paste").children("a").attr("href",svr.replace(",'s",",'paste="));$(".delete").children("a").attr("href",svr.replace(",'s",",'delete="));returnfalse;}}});
/*Genericcontextmenustyles*/.contextMenu{position:absolute;width:120px;z-index:99999;border:solid1px#CCC;background:#EEE;padding:0px;margin:0px;display:none;}.contextMenuLI{list-style:none;padding:0px;margin:0px;}.contextMenuA{color:#333;text-decoration:none;display:block;line-height:20px;height:20px;background-position:6pxcenter;background-repeat:no-repeat;outline:none;padding:1px5px;padding-left:28px;}.contextMenuLI.hoverA{color:#FFF;background-color:#3399FF;}.contextMenuLI.disabledA{color:#AAA;cursor:default;}.contextMenuLI.hover.disabledA{background-color:transparent;}.contextMenuLI.separator{border-top:solid1px#CCC;}/*AddingIconsYoucanaddiconstothecontextmenubyaddingclassestotherespectiveLIelement(s)*/.contextMenuLI.editA{background-image:url(images/page_white_edit.png);}.contextMenuLI.cutA{background-image:url(images/cut.png);}.contextMenuLI.copyA{background-image:url(images/page_white_copy.png);}.contextMenuLI.pasteA{background-image:url(images/page_white_paste.png);}.contextMenuLI.deleteA{background-image:url(images/page_white_delete.png);}.contextMenuLI.quitA{background-image:url(images/door.png);}