ASTreeView – How to disable checkbox PostBack

by Weijie JIN on

There’s a request that to disable the checkbox PostBack while the AutoPostBack properties is set to true. Because for node selection, we want to enable the PostBack.

By default, if we set the AutoPostBack properties of ASTreeView, both the checkbox and selection will be effected.

So here we need a little tricky to achieve that:

First, in the aspx page, we need to remove the postback related attribute for the checkbox, here’s the javascript function you can put into your aspx page:

<script type="text/javascript">
	function clearCheckboxPostBackEvent(){
		var cbs = document.getElementsByTagName("IMG");
		for( var i = 0; i < cbs.length; i++ )
		{
			if( cbs[i].className == "astreeview-checkbox" ){
				cbs[i].setAttribute("postbackscript","");										
			}
		}	
	}
</script>

Then, in the code behind, in Page_Load event handler, you call the javascript function above:

protected void Page_Load( object sender, EventArgs e )
{
	string clearCheckboxPostbackScript = "clearCheckboxPostBackEvent();";
	ScriptManager sm = ScriptManager.GetCurrent( this );
	if( sm != null && sm.EnablePartialRendering )
		ScriptManager.RegisterStartupScript( this
										, this.GetType()
										, "clearCBPostback"
										, clearCheckboxPostbackScript
										, true );
	else
		ClientScript.RegisterStartupScript( this.GetType()
										, "clearCBPostback"
										, clearCheckboxPostbackScript
										, true );

}

That’s it, the result will be: the selection postback is activated and the checkbox won’t perform postback by clicking.

  • xiaoyq

    看了你的控件,非常棒。
    提个建议,你的网站可以加一个留言功能,方便别人提建议或购买,我找了半天都不知道如何才能和你沟通上。只好在评论上留个言,不知你能否看到。

    你的astreeview有个功能没有提供。
    用户点击展开或收缩的时候需要触发事件怎么办??

  • http://www.jinweijie.com jinweijie

    谢谢支持,联系方式可以用support页面上的email

    展开/收缩暂时没有开放事件,我会考虑在下个版本增加,谢谢。

  • wp

    你好,在你最新发布的版本之中好像不支持用DataTable来进行绑定了是吗?谢谢

  • http://www.jinweijie.com jinweijie

    支持datatable的

  • catman

    XML 数据源方式,不能在数据源中添加自己定义的属性,否则绑定的时候会出错:
    The ‘code’ attribute is not declared.
    而这是很必要的,因为需要根据这个属性来搜索 XML 节点,以便添加后续的 XML 节点,现在的做法我只能是先添加自己定义的属性,然后在绑定之前再把这些属性删除。

    另外,XML 数据源格式,不知道为什么要加一个 ,直接后面跟 节点不是更方便吗?

  • http://www.jinweijie.com jinweijie

    你可以不用XmlDataSourceDescriptor,你可以自己创建DataSourceDescriptor

  • Ajay

    have a simple question. how do we set a checkbox state from client side javascript? I tried the setAttribute method, but the checkbox was unchanged. Can you please help?

  • http://www.jinweijie.com jinweijie

    Hi, could you please submit your requests to mantis? all the request will be queued. you can find the link here: http://www.astreeview.com/astreeviewdemo/Support.aspx

    thanks.

  • http://www.scribd.com/doc/58682879/Online-Money-Making-Ideas Kayce Warneka

    I value the effort you’ve taken to post. Continue the very good work.

Previous post:

Next post: