日期:2014-05-17  浏览次数:20488 次

帮忙看下这段代码为何在运行时提示对象不支持此属性或方法
[code=C#][/code]<%@ Page Title="" Language="C#" MasterPageFile="~/userinfo/MasterPage.master" AutoEventWireup="true" CodeFile="ModInfo.aspx.cs" Inherits="userinfo_ModInfo" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<link type="text/css" href="css/main.css" rel="stylesheet"/>
<script type="text/javascript">
  function filepath() {
// document.getElementById("ContentPlaceHolder1_Uploader").select(); //选中FileUpload控件中的文本  
// var path = document.selection.createRange().text; //获取当前文本选中的文本
// document.getElementById("filepath").value = path;
  alert('abc');
  }
  </script>
<form id="form1" runat="server">
<div>
 <div class="biao"> <asp:Label ID="topic" runat="server" Text="头像设置:"></asp:Label>
  </div></div>
  <br />
  <div class="conten">
  <asp:Image ID="userface" runat="server" Height="128px" Width="128px" 
  ImageUrl="~/userinfo/face/celine.gif" />
  <br />
  <asp:Label ID="labelresult" runat="server" Text=""></asp:Label>
   
  <br />
  <br />
   
  <asp:FileUpload ID="Uploader" runat="server"/>
   
  &nbsp;<br />
  <br />
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
   
  <asp:Button ID="Button1" runat="server" Text="上传" onclick="Button1_Click" OnClientClick="return filepath();" />
  <input type="button" id="input" name="input" onclick="return filepath()" />
  &nbsp; (只支持JPG格式)<br />
  <br />
  <asp:HiddenField ID="imginfo" runat="server" />
  <input type="hidden" id="filepath" name="filepath" />
  <br />
  </div>
</form>
</asp:Content>



------解决方案--------------------
<asp:Button ID="Button1" runat="server" Text="上传" onclick="Button1_Click" OnClientClick="return filepath();" />

==>>>>>>

 <asp:Button ID="Button1" runat="server" Text="上传" ></asp:Button>
在CS文件中的 page_onload 事件中 写
 Button1.Attributes.Add("onclick","return filepath();");
------解决方案--------------------
filepath()方法名改成aaa()看看再说