是这样的,我是把mscrm中的htc下下来,自己写了一个combo控件,但遇到一个问题
就是我把combo控件,放在页面中,页面上的按钮事件不能触发,点击按钮时,跟踪时发现它每次
居然跳到combo的RaisePostBackEvent事件
public class Combo : System.Web.UI.WebControls.WebControl,IPostBackEventHandler
protected override void Render(HtmlTextWriter output)
{
略,只是加入了在<span class="selectBox"..
而selectbox { behavior: url("+GetVPath()+@"/Combo/select.htc)}
}public void RaisePostBackEvent(string eventArgument)
{
if (eventArgument=="onchange")
OnChange();

}如果把hehavior ;url htc去除,就没事,加上就会出现以上的问题
请问可能是什么原因?

解决方案 »

  1.   

    以下是select.htc
    <public:component lightweight="true">
    <public:attach event="oncontentready" onevent="init()"/>
    <public:attach event="onmouseup" onevent="mouseUp()"/>
    <public:attach event="onkeydown" onevent="handleKey()"/>
    <public:attach event="onblur"           onevent="onBlur()"/>
    <public:method name="on"/>
    <public:method name="disable"/>
    <public:method name="enable"/>
    <public:method name="setOpen"/>
    <public:method name="handleClick"/>
    <public:method name="reset"/>
    <public:method name="setValue"/>
    <public:method name="getValueIndex"/>
    <public:method name="getValue"/>
    <public:property name="req" value="0"/>
    <public:property id="allowValueEditProperty" name="allowValueEdit" get="getAllowValueEdit" put="setAllowValueEdit"/>
    <public:property id="returnValueProperty" name="returnValue" get="getReturnValue"/>
    <public:property name="isInitialized" get="getInitialized"/>
    <public:event id="eventOnReturnValueChange" name="onreturnvaluechange"/>
    <!-- Set event.returnValue to true if the data is valid, false otherwise.  Set event.formattedValue to the appropriate formatted value (to pretty up user input, for example)  -->
    <public:event id="eventOnValidate" name="onvalidate"/>
    <!-- Set event.sEntry the entry immediately preceding event.inputValue in the list.  Ex: if inputValue == "12:42", sEntry would equal "12:00" -->
    <public:event id="eventOnFindNextSmallestEntry" name="onfindnextsmallestentry"/>
    <public:event id="eventOnInitComplete" name="oninitcomplete"/>
    <script language="JavaScript">
    var _iY = 121;
    var _Vpath;
    var _oTbl, _oIn, _oPop,_oVal;
    var _bOpen = false;
    var _bAllowValueEdit = false;
    var _bInOnBlur = false;
    var _bIsInitialized = false;
    var VALUE_DOESNT_EXIST = -1;
    var VALUE_IS_CUSTOM = -2;
    var KEY_UP = 38;
    var KEY_DOWN = 40;
    var KEY_ENTER = 13;
    var KEY_DLE = 16;
    var KEY_TAB = 9;
    function init()
    {
    if(ValueEdit=="true")
    _bAllowValueEdit=true;
    if (window.document.media == "print")
    {
    return false;
    }
    _Vpath=Vpath;
    var s = "<table onmouseout='parentElement.setOpen();' onmouseover='parentElement.setOpen();' style='table-layout:fixed;width:100%;' cellspacing=0 cellpadding=0><col><col width=18><tr><td><input crmType='sel' onkeydown='if(event.keyCode==27)return false;'";
    if (this.changeHandler) s += " onchange=\"if(returnValue!=lastValue){" + changeHandler + "(this);}\"";
    if (this.tabbingIndex) s += " tabindex=\"" + tabbingIndex + "\"";
    if (!_bAllowValueEdit)
    {
    s += " contenteditable='false'";
    }
    s += " onselectstart='if (!parentElement.parentElement.parentElement.parentElement.parentElement.allowValueEdit){return false;}else{return true;}' class='selectBox' onfocus=\"if (!parentElement.parentElement.parentElement.parentElement.parentElement.allowValueEdit){runtimeStyle.backgroundColor='#abc0e7'};\" onblur=\"runtimeStyle.backgroundColor='';\" lastValue=\"" + value + "\" returnValue=\"" + value + "\" name=\"" + name + "\"></td><td><img onmouseover=\"if (!disabled) src='"+_Vpath+"/combo/selectOn.gif';\" onmouseout=\"if (!disabled) src='"+_Vpath+"/combo/selectOff.gif';\" style='cursor:hand;' align='absmiddle' src='"+_Vpath+"/combo/selectOff.gif'></td></tr></table>" + innerHTML;
    s +="<input type=text onkeydown='if(event.keyCode==27)return false;' style='display:none' name='"+name+"_val'>"
    innerHTML = s;
    var i = 0;
    var iRowCount = children[1].rows.length;
    while (i < iRowCount)
    {
    if (children[1].rows[i].cells[0].val == value) break;
    i++;
    }


    if (i >= iRowCount)
    {

    i = (value.length == 0) ? 0 : VALUE_IS_CUSTOM;
    }

    _oIn = firstChild.rows[0].cells[0].firstChild;
    _oVal=lastChild;

    var m_haveinit=false;
    if(_bAllowValueEdit)
    {
    if(CText)
    {
    _oIn.value = CText;
    _oIn.returnValue = "";
    m_haveinit=true;
    }
    }
    if(!m_haveinit)
    {
    if (isListItemRow(i))
    {
    _oIn.value = children[1].rows[i].cells[0].innerText;
    _oIn.returnValue = children[1].rows[i].cells[0].val;
    }
    else
    {
    _oIn.value = value;
    _oIn.returnValue = value;
    }
    }
    _oVal.value=_oIn.returnValue;

    _oIn.defaultValue = _oIn.returnValue;
    _oIn.rowNum = getValueIndex(_oIn.returnValue);
    _oIn.htc = this;
    _oIn.req = req;
    _oIn.attachEvent("onblur", onBlur);

    setAllowValueEdit(_bAllowValueEdit);
    if (this.element.disabled)
    {
    disable();
    }
    _bIsInitialized = true;
    setAllowValueEdit(_bAllowValueEdit);
    if (this.setdisabled)
    {
    internalDisable(true);
    }
    this.oldValue_i=_oVal.value;

    eventOnInitComplete.fire();
    }
    function getSurroundingEntries(sValue)
    {

    var oRVal = new Object();

    if (isListItemRow(_oIn.rowNum))
    {
    oRVal.iPrevious = _oIn.rowNum - 1;
    oRVal.iNext     = _oIn.rowNum + 1;
    }
    else
    {

    var oEvent = createEventObject();
    oEvent.inputValue = sValue;
    eventOnFindNextSmallestEntry.fire(oEvent);
    if (typeof(oEvent.sEntry) != "undefined")
    {
    var iIndex = getValueIndex(oEvent.sEntry);
    oRVal.iPrevious = iIndex;
    oRVal.iNext     = iIndex + 1;
    }
    else
    {

    oRVal.iPrevious = 0;
    oRVal.iNext     = 1;
    }
    }

    if (oRVal.iPrevious < 0)
    {
    oRVal.iPrevious = 0;
    oRVal.iNext = (_oTbl.rows.length > 1) ? 1 : 0;
    }
    else if (oRVal.iNext >= _oTbl.rows.length)
    {
    oRVal.iNext = _oTbl.rows.length - 1;
    oRVal.iPrevious = (_oTbl.rows.length > 1) ? oRVal.iNext - 1 : oRVal.iNext;
    }
    return oRVal;
    }
    function getInitialized()
    {
    return _bIsInitialized;
    }
    function onBlur()
    {


    if (_bInOnBlur) return;

    _bInOnBlur = true;

    if (_bAllowValueEdit)
    {
    var oResult = isValidInput(_oIn.value);
    if (oResult.isValid)
    {

    _oIn.value       = oResult.sFormattedInput;
    _oIn.returnValue = oResult.sFormattedInput;
    _oVal.value=_oIn.returnValue;
    fireReturnValChange( );

    _oIn.rowNum = getValueIndex(_oIn.returnValue);
    }
    else
    {
    _oIn.value = _oIn.returnValue;
    }
    }
    _bInOnBlur = false;
    }
      

  2.   

    function isValidInput(sInput)
    {

    var oEvent = createEventObject();
    oEvent.inputValue = _oIn.value;
    eventOnValidate.fire(oEvent);
    oResult = new Object();
    if (typeof(oEvent.returnValue) == "undefined")
    {

    oResult.isValid = true;
    oResult.sFormattedInput = sInput;
    }
    else if (oEvent.returnValue == true)
    {

    oResult.sFormattedInput = oEvent.formattedValue;
    oResult.isValid = true;
    }
    else
    {
    oResult.isValid = false;
    }
    return oResult;
    }
    function getReturnValue()
    {
    return _oIn.returnValue;
    }
    function getAllowValueEdit()
    {
    return _bAllowValueEdit;
    }
    function setAllowValueEdit(bAllow)
    {
    _bAllowValueEdit = bAllow;



    if (readyState == "complete" && _bIsInitialized)
    {
    _oIn.contentEditable = bAllow;
    allowValueEditProperty.fireChange();
    }
    }
    function getValue(i)
    {
    var oRows = this.children[1].rows;
    if (i < 0 || i >= oRows.length)
    {
    return false;
    }
    return oRows[i].cells[0].val;
    }
    function getValueIndex(sVal)
    {
    if (sVal == "")
    {
    return VALUE_DOESNT_EXIST;
    }
    var oRows = this.children[1].rows;
    for (var i = 0; i < oRows.length; i++)
    {
    if (oRows[i].cells[0].val == sVal)
    {
    return i;
    }
    }
    return VALUE_IS_CUSTOM;
    }
    function setValue(sVal)
    {
    var iRow = getValueIndex(sVal);
    if (isListItemRow(iRow))
    {
    setVals(iRow);
    }
    else
    {

    _oIn.value = sVal;
    _oIn.returnValue = sVal;
    _oVal.value=_oIn.returnValue;

    _oIn.rowNum = iRow;
    fireReturnValChange( );
    }
    }
    function fireReturnValChange( )
    {
    if(this.oldValue_i==_oVal.value)
    return;
    this.oldValue_i=_oVal.value;
    returnValueProperty.fireChange( );
    var oEvent = createEventObject();
    eventOnReturnValueChange.fire( oEvent );
    }
    function initBox()
    {
    if (children[1].bCached) return;
    children[1].bCached = true;

    _oPop = openPopup(); var oCol = element.document.createElement("COL");
    with (oCol.style) 
    {
    paddingLeft = "5px";
    cursor = "default";
    fontSize = "11px";
    fontFamily = "verdana";
    }
    with (children[1]) 
    {
    firstChild.insertBefore(oCol);
    onmouseover = "this.box.on(event);";
    onselectstart = "return false;";
    onclick = "this.box.handleClick(event);";
    style.width = "100%";
    }

    if (children[1].rows.length <= 6) _iY = (children[1].rows.length * 17) + 2;
    _oPop.document.body.innerHTML = "<span style='width:100%; height:" + _iY + "px; border:1px solid #000000; overflow-y:auto; overflow-x:hidden;'>" + children[1].outerHTML + "</span>";

    _oTbl = _oPop.document.body.firstChild.firstChild;
    _oTbl.style.display = "inline";
    _oTbl.box = this;
    }
    function mouseUp()
    {

    if (_oIn.disabled || (_bAllowValueEdit && event.srcElement.tagName == "INPUT"))
    {
    return;
    }
    _oIn.focus();
    if (!_bOpen)
    {
    showBox();
    focus();
    }
    _bOpen = !_bOpen;
    }
    function hideBox()
    {
    _bOpen = false;
    try
    {
    _oPop.hide();
    _oIn.focus();
    _oIn.fireEvent("onchange");
    if (isListItemRow(_oIn.rowNum))
    {
    setColor(_oIn,_oTbl.rows[_oIn.rowNum]);
    }
    }
    catch (e)
    {
    return false;
    }
    }
    function reset()
    {
    children[1].bCached = false;
    _oIn.rowNum = 0;
    }
    function internalDisable(b)
    {
    var oTR = element.children[0].children[1].children[0];
    var oSelectBox = oTR.children[0].children[0];
    var oImg = oTR.children[1].children[0];
    if (b)
    {
    s = "default";

    oSelectBox.runtimeStyle.borderColor = "#cccccc";
    oSelectBox.className = "selectBox ro";
    oImg.className = "ro";
    oImg.src = _Vpath+"/combo/selectGrey.gif";
    }
    else
    {
    s = "hand";

    oSelectBox.runtimeStyle.borderColor = "";
    oSelectBox.className = "selectBox";
    oImg.className = "selectBox";
    oImg.src = _Vpath+"/combo/selectOff.gif";
    }

    oSelectBox.disabled = b;
    with (element.children[0].rows[0])
    {
    cells[1].firstChild.style.cursor = s;
    cells[1].firstChild.disabled = b;
    disabled = b;
    }
    element.disabled = b;
    }
    function enable()
    {
    internalDisable(false);
    }
    function disable()
    {
    internalDisable(true);
    }
      

  3.   

    function setOpen()
    {
    _bOpen = (_oPop && _oPop.isOpen);
    }
    function showBox()
    {

    _oIn.rowNum = getValueIndex(_oIn.returnValue);
    initBox();
    setDefault();
    _oPop.show(0, 19, clientWidth, _iY, firstChild);


    var iTopIndex;
    if (isListItemRow(_oIn.rowNum))
    {
    iTopIndex = _oIn.rowNum;
    }
    else
    {
    oResult = getSurroundingEntries(_oIn.returnValue);
    iTopIndex = oResult.iPrevious;
    }

    var span = _oPop.document.body.firstChild;


    span.scrollTop = span.firstChild.firstChild.children[iTopIndex].offsetTop;
    }
    function on(o)
    {
    o = o.srcElement.parentElement;
    if (o.tagName == "TR")
    {
    setColor(o,_oTbl.rows[_oIn.rowNum]);
    _oIn.rowNum = o.rowIndex;
    }
    }
    function handleClick(o)
    {
    if (o.srcElement.parentElement.rowIndex >= 0)
    {
    _oIn.rowNum = o.srcElement.parentElement.rowIndex;
    setVals(_oIn.rowNum);
    hideBox();
    }
    }
    function handleKey()
    {
    var i = event.keyCode;
    if (i == KEY_TAB && _bOpen)
    {


    _oIn.focus();
    return;
    }
    switch (i)
    {
    case KEY_UP: case KEY_DOWN: case KEY_ENTER:
    initBox();
    if (!_bOpen) setDefault();
    if (i != KEY_ENTER && event.altKey)
    {
    _oPop.isOpen ? hideBox() : showBox();
    return;
    }
    break;
    default: return;
    }

    if (_bAllowValueEdit)
    {



    if (_oIn.value != _oIn.returnValue)
    {

    var oResult = isValidInput(_oIn.value);
    if (oResult.isValid)
    {



    _oIn.rowNum = getValueIndex(oResult.sFormattedInput); 



    _oIn.returnValue = oResult.sFormattedInput;
    _oVal.value=_oIn.returnValue;
    }
    }
    }
    switch (i)
    {
    case KEY_UP:

    oResult = getSurroundingEntries(_oIn.returnValue);
    if (oResult.iPrevious == _oIn.rowNum)
    {
    break; 
    }
    var oPreviousEntry;
    if (isListItemRow(_oIn.rowNum))
    {
    oPreviousEntry = _oTbl.rows[_oIn.rowNum];
    }
    else
    {

    oPreviousEntry = null;
    }
    var oNewEntry = _oTbl.rows[oResult.iPrevious];
    setColor(oNewEntry, oPreviousEntry, true);
    setVals(oResult.iPrevious);

    _oIn.fireEvent("onchange");
    break;
    case KEY_DOWN:

    oResult = getSurroundingEntries(_oIn.returnValue);
    if (oResult.iNext == _oIn.rowNum)
    {

    break;
    }
    var oPreviousEntry;
    if (isListItemRow(_oIn.rowNum))
    {
    oPreviousEntry = _oTbl.rows[_oIn.rowNum];
    }
    else
    {

    oPreviousEntry = null;
    }
    var oNewEntry = _oTbl.rows[oResult.iNext];
    setColor(oNewEntry, oPreviousEntry, true);
    setVals(oResult.iNext);


    _oIn.fireEvent("onchange");
    break;
    case KEY_ENTER:
    hideBox();
    break;
    }

    event.cancelBubble = true;
    event.returnValue = false;
    }
    function setVals(_iIndex)
    {
    with (element.children[1].rows[_iIndex].cells[0])
    {
    _oIn.lastValue = _oIn.returnValue;
    _oIn.value = innerText;
    _oIn.returnValue = val;
    _oVal.value=_oIn.returnValue;
    _oIn.rowNum = _iIndex;
    }

    fireReturnValChange( );
    }
    function setColor(oOn, oOff, bScroll)
    {
    if (bScroll) oOn.scrollIntoView();
    if (oOn != oOff)
    {
    if (oOn != null)
    {
    oOn.runtimeStyle.backgroundColor = "#abc0e7";
    }
    if (oOff != null)
    {
    oOff.runtimeStyle.backgroundColor = "";
    }
    }
    }
    function setDefault()
    {

    var oRows = _oTbl.rows;
    for (var i = 0; i < oRows.length; i++)
    {
    setColor(null, oRows[i]);
    }
    if (isListItemRow(_oIn.rowNum))
    {
    setColor(_oTbl.rows[_oIn.rowNum], null);
    }
    }
    function isListItemRow(iRowId)
    {
    return(iRowId != VALUE_DOESNT_EXIST && iRowId != VALUE_IS_CUSTOM);
    }
    </script>
    </public:component>
      

  4.   

    解析过的html没有什么<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title>WebForm14</title>
    <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
    <meta content="C#" name="CODE_LANGUAGE">
    <meta content="JavaScript" name="vs_defaultClientScript">
    <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">

    </HEAD>
    <body MS_POSITIONING="GridLayout">
    <form name="Form1" method="post" action="WebForm14.aspx" id="Form1">
    <input type="hidden" name="__VIEWSTATE" value="dDw2MzI2MjY2MDM7dDw7bDxpPDE+Oz47bDx0PDtsPGk8Nj47PjtsPHQ8cDxwPGw8YXJyVGV4dDthcnJWYWx1ZTtWYWx1ZUVkaXQ7Y29tYm9fYWxpZ247PjtsPEA8YWFhO2JiYjtjY2M7PjtAPDE7MjszOz47bzxmPjtcZTs+Pjs+Ozs+Oz4+Oz4+Oz6pBTsZn1xjIqsKF0ZXo0QyLxkajg==" />
    <style> input.selectBox { width: 100%; height: 19px; border: 1px solid #7b9ebd; border-right: 0px; padding-left: 5px; font-size: 11px; font-family: verdana; cursor: default; } div.selectBox { width: 100%; height: 19px; border: 1px solid #7b9ebd; border-right: 0px; padding-left: 5px; font-size: 11px; font-family: verdana; cursor: default; } span.selectBox { height: 21px;  behavior: url(/webUserWindowExample//Combo/select.htc);}</style><script>function openPopup(){return window.createPopup();}</script><input type="submit" name="Button1" value="Button" id="Button1" style="Z-INDEX: 104; LEFT: 232px; POSITION: absolute; TOP: 112px" />

    <table border=0 cellspacing='0' cellpadding='0' width='' style='display:online;TABLE-LAYOUT:fixed' style=';Z-INDEX:106;LEFT:352px;POSITION:absolute;TOP:72px'><tr><td><span tabbingIndex='0'  onreturnvaluechange="aaaa(this);__doPostBack('Combo1','xxxx')" ValueEdit='false' Vpath='/webUserWindowExample/' class='selectBox' name='Combo1' id='Combo1'  value=''><table cellspacing='0' cellpadding='2' style='DISPLAY:none'><tr><td nowrap val='1'>aaa</td></tr><tr><td nowrap val='2'>bbb</td></tr><tr><td nowrap val='3'>ccc</td></tr></table></span></td></tr></table>
    <input type="hidden" name="__EVENTTARGET" value="" />
    <input type="hidden" name="__EVENTARGUMENT" value="" />
    <script language="javascript" type="text/javascript">
    <!--
    function __doPostBack(eventTarget, eventArgument) {
    var theform;
    if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
    theform = document.Form1;
    }
    else {
    theform = document.forms["Form1"];
    }
    theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
    theform.__EVENTARGUMENT.value = eventArgument;
    theform.submit();
    }
    // -->
    </script>
    </form>
    </body>
    </HTML>
      

  5.   

    cannot tell what's wrong in the code shown, what else in your Combo class? are you also outputing the UniqueID? also try to implement a er interfacepublic class Combo : System.Web.UI.WebControls.WebControl,INamingContainer, IPostBackEventHandleralso, use Page.GetPostBackEventReference Method (Control, String), don't use __doPostBack directly
      

  6.   

    onreturnvaluechange="aaaa(this);
    //aaaa(e) 在哪里定义的?
      

  7.   

    sent me the files, I sent you my email in 短消息
      

  8.   

    谢谢各位,以及思归大侠,
    真是个笑话,我在以前的页面中出现问题,我今天把相关代码,放到一个新的工程中,准备打包发给思归大侠看一下,可是我运行了一下,居然没有问题了。到现在我也没明白是什么回事,可能是我重新装了vs.net的原因。或者如zsms2(SharpSun)所说,可能存在不可见字符,你的js 没有通过总之感谢各位关注,祝大家春节愉快。