function getfile(obj)
       {     
             var arrList = obj.value.split(".")
             var flag=0;
             var filez=new Array("doc","DOC","docx","DOCX")
       
             for(var i=0;i<filez.length;i++)
             {
                if(filez[i]==arrList[arrList.length-1])
                {
                    flag=1;
                }
             }
             if(flag==0)
             {
                alert('请选择word文档');
                document.getElementById("ctl00_ContentPlaceHolder1_TabContainer1_TabPanel2_FULword").outerHTML = document.getElementById("ctl00_ContentPlaceHolder1_TabContainer1_TabPanel2_FULword").outerHTML;
             }
             if(flag==1)
             {
                alert("hahahaha");
//                document.getElementById("ctl00_ContentPlaceHolder1_TabContainer1_TabPanel2_FULword").outerHTML = document.getElementById("ctl00_ContentPlaceHolder1_TabContainer1_TabPanel2_FULword").outerHTML;
                
                alert(obj.value);
                document.getElementById("ctl00_ContentPlaceHolder1_TabContainer1_TabPanel2_FULword").value="aaaaaaa";
                alert(document.getElementById("ctl00_ContentPlaceHolder1_TabContainer1_TabPanel2_FULword").value);
             }
             
       }
    function choosefile()
    {
        document.getElementById("ctl00_ContentPlaceHolder1_TabContainer1_TabPanel2_FULword").click();
//        if(document.getElementById("ctl00_ContentPlaceHolder1_TabContainer1_TabPanel2_FULword"))
        alert("方法二");
        return true;
    }<span style="display:none;">
<asp:FileUpload ID="FULword" runat="server" Width="143px" onchange="javascript:getfile(this);" onkeydown= "event.returnValue=false; "   onpaste= "return   false " />
</span> 
<asp:Button ID="btnok" runat="server" Text="Button" Width="63px" OnClientClick="return choosefile();" OnClick="btnok_Click"  />
点击按钮选择文件后上传
我想通过true和false 控制后台刷新 可是有这段
("ctl00_ContentPlaceHolder1_TabContainer1_TabPanel2_FULword").outerHTML = document.getElementById("ctl00_ContentPlaceHolder1_TabContainer1_TabPanel2_FULword").outerHTML
才刷新不知为什么,在线等

解决方案 »

  1.   

    还不是非常理解题意,不过LZ试试这个方法看:1、把OnClientClick="return choosefile()";去掉;
    2、在后台的Page_Load中第一行吧,加入如下代码:btnok.Attributes.Add("onclick","return choosefile()");
      

  2.   

    一般 JS 方法 返回true 执行后台方法,返回false 就不执行。
      

  3.   

    点击按钮触发choosefile,执行FileUpload 的click事件,选择word文件则执行后台事件否则不执行后台(通过choosefile的返回值true和false触发是否执行后台,现在是设为true始终不执行后台)
      

  4.   

    我发现自己的理解能力越来越差了,不说别的,单就:("ctl00_ContentPlaceHolder1_TabContainer1_TabPanel2_FULword")
    这种风格的代码,我不敢苟同.
      

  5.   

    有没有什么其他方法 只需要一个按钮 不用FileUpload 
      

  6.   

    比较奇怪的是 加上:
    document.getElementById("FULword").outerHTML = document.getElementById("FULword").outerHTML;
    就可以执行后台 不加就执行 
    但上传又不能清空
      

  7.   

    但可通过css做假,表面上点的其他,其实是点击file控件.
      

  8.   

    只用FileUpload不用其他按钮可以实现上传吗 
      

  9.   

     http://blog.csdn.net/cpp2017/archive/2009/08/06/4418202.aspx