思路话语

。Arlen:思想有多远你就能走多远...

用户控件 MagicAjax 选择器 __doPostBack

最近在做的系统中用到的选择器,因为赶时间暂时做了用户控件。
但是由于想将该控件放到MagicAjaxPanel中防止刷新,结果是无法打开选择器的模态窗口。
已经做成自定义控件的选择器不存在这个问题。
于是寻找原因,最后将Panel套到用户控件里面的TextBox外面,就可以了。

用户控件里的html:

<%@ Control Language="c#" AutoEventWireup="false" Codebehind="ServiceChooser.ascx.cs" Inherits="Tencent.ITIL.ItilRequest.ItilRequestWeb.UserControl.ServiceChooser" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
<%@ Register TagPrefix="ajax" Namespace="MagicAjax.UI.Controls" Assembly="MagicAjax" %>
<script>
/*
        function openDialog3(srcW,srcH,srcU,sl) 
        {    
            var X=0;
            var Y=0;
            var Cstyle;
            X=(screen.width-srcW)/2;
            Y=(screen.height-srcH)/2;
            Cstyle = "dialogLeft:"+X+"px;dialogTop:"+Y+"px;dialogHeight:"+srcH+"px;dialogWidth:"+srcW+"px;help:no;status:no;scroll:"+sl;
            var sReturnVal = window.showModalDialog(srcU,window,Cstyle);
            return sReturnVal;
        }
        
*/

        
function GetValue(postback)
        
{
            
//目前已经选中的值
            var selectedValues = document.getElementById("<%=hdId.ClientID%>").value;
            
var params = "";
            
if(selectedValues != "" && selectedValues != ";")
            
{
                params 
= "id=" + selectedValues;
            }

            
            
var url = "../Web/ServiceSelector.aspx";
            
if(params != "")
            
{
                url 
+= "?" + params;
            }

            
var result = openDialog2('550','400',url,'no');
            
            
            
var oldId = document.getElementById("<%=hdId.ClientID%>").value;
            
if(result)
            
{
                
var serviceIds = result[0];
                
var serviceNames = result[1];
                document.getElementById(
"<%=hdId.ClientID%>").value = serviceIds;
                document.getElementById(
"<%=txtName.ClientID%>").value = serviceNames;                
                
            }

                        
            
//var attr = document.getElementById("<%=this.ClientID%>").getAttribute("AutoPostback");            
            
            
            
if(postback.toLowerCase() == "true" && oldId != document.getElementById("<%=hdId.ClientID%>").value)
            
{
                __doPostBack('
<%=txtName.ClientID%>','');
            }

            
        }

</script>
<ajax:ajaxpanel id="Ajaxpanel1" runat="server">
  
<asp:textbox id="txtName" ReadOnly="True" runat="server" Width="180px"></asp:textbox>
</ajax:ajaxpanel>
&nbsp;
<IMG style="CURSOR: hand" onclick="GetValue('<%=AutoPostBack%>');" src="/tof_client/images/addrbook.gif"> 
<INPUT id="hdId" type="hidden" name="hdId" runat="server">


用户控件后台代码:
//.
public bool AutoPostBack
        
{
            
get
            
{                
                
return txtName.AutoPostBack;
            }

            
set
            
{
                txtName.AutoPostBack 
= value;
            }

        }



public event System.EventHandler SelectedChanged;

//.

private void txtName_TextChanged(object sender, System.EventArgs e)
        
{
            SelectedChanged(
null,null);
        }



注意:
1.JS中的__doPostBack方法的调用,如果第一个参数传空,则无论怎样都会刷新整个页。必须传入txtName的ID。
2.下面这一段在GetValue里执行不会成功。因为在解释这段JS的时候,IE检测不到后台定义的AutoPostBack属性(这时候还没加载dll,所以找不到?)
var attr = document.getElementById("<%=this.ClientID%>").getAttribute("AutoPostback");  

posted on 2007-07-20 16:06  Arlen  阅读(597)  评论(1编辑  收藏  举报

导航