不知道你的用户控件在什么位置,是放在界面上的还是在代码里加的,页面显示完后IsPostBack就是true了,除非你再次用刷新,否则响应控件的事件的话IsPostBack就会是true

解决方案 »

  1.   

    首次加载时就加载了控件;
    this.IsPostBack指的同一个页面;这两个都是正确的
      

  2.   

    谢谢两位,我页面里面,GridView编辑状态里有一个用户自定义DropDownList,想首次加载时绑定DropDownList的内容,不知道怎么实现?
      

  3.   

    this.ispostback就是同一页面的if(!this.ispostback)
    {
    数据链接,
    绑定
    }
      

  4.   

    IsPostBack是页面状态,跟控件无关。控件的 IsPostBack 是返回所在的页面的 IsPostBack。早期的超级简单的页面例子程序比较常用IsPostBack,这样初学者就省得自己写几行代码、写一个标志到ViewState了。但是不要把这个盲目附会到自定义控件身上。你说的“自定义DropDownList”问题,我不懂你说的“首次加载”是个什么概念。当一条记录从进入或者离开编辑状态时,DropDownList重建或者不重建,什么动作算作首次加载?
      

  5.   


    谢谢两位,我页面里面,GridView编辑状态里有一个用户自定义DropDownList,想首次加载时绑定DropDownList的内容,不知道怎么实现?
    -------------------------------------------------
    放在if(!IsPostBack)
    {
      load your DropDownList Data
    }
      

  6.   

    楼上,你打算如何把握住 DropDownList 控件的,给个代码?
      

  7.   

    这是我原来做的一个动态增加附件和附件标题的东西,给你贴出来你让你看看怎 么实现动态添加控件 (run time at vs2003)
    --------------------------------------------------------
    前台JS//增加控件
    function addClientControls()
    {
    var count_obj;
    var tr_obj;
    var td_obj;
    var file_obj;
    var form_obj;
    var count;
    var table_obj;
    var button_obj;
    var countview_obj;
    var str1;
    var str2;
    form_obj=document.getElementById("Form1");

    fj_obj=document.getElementById("td_fj");

    if(fj_obj.innertext=="无附件")
    {
    fj_obj.innertext="";
    }

    count_obj=document.getElementById("count_obj"); if (count_obj==null)
    {
    count_obj=document.createElement("input");
    count_obj.type="hidden";
    count_obj.id="count_obj";
    count_obj.value=1;

    form_obj.appendChild(count_obj);
    count=1;
    count_obj.value=1;
    }
    else
    {
    count_obj=document.getElementById("count_obj");
    count=Number(count_obj.value)+1;
    count_obj.value=count;
    }

    div_obj=document.createElement("div");
    div_obj.id="div_" + count;
    div_obj.align="center";

    fj_obj.appendChild(div_obj);

    str1="附件名称:<input type='file' name='fj"+count+"' size=55 class='input' id=fj"+count+">";
    str2="<br>附件标题:<input type='text' name='fjsm"+count+"' class='input' size=55 maxlength=100 id='fjsm"+count+"'>";
    str3="<input type='button' class='button' value='删除本条' onclick=javascript:delClientControls("+"\""+div_obj.id+"\""+"); id='button"+count+"' name='button"+count+"'>";       
    div_obj.innerHTML=str1+str2+str3;
    }//删除控件
    function delClientControls(id) 
    {
    var child;
    var parent;
    var count_obj; child=document.getElementById(id);
    count_obj=document.getElementById("count_obj");

    if(child==null)
    {
    alert("对象为空");
    }
    else
    {
    child.removeNode(true)
    count_obj.value=Number(count_obj.value)-1;
    if(count_obj.value=="0")
    {
    count_obj.removeNode(true);
    }

    }  parent=document.getElementById("td_fj");

    if(!parent.hasChildNodes)
    {
    parent.innerText="";

    }
    }
    -----------------------------------------------------------
    aspx file
    ----------------------------
    <tr class="InputFrameButtonLine">
    <td align="center"><input class="button" onclick="addClientControls()" type="button" value="新增附件" name="button_xzfj">
    <INPUT class="button" id="button3" onclick="postClientCheck()" type="button" value="保存">
    <input class="button" id="button2" onclick="javascript:history.back(0)" type="button" value="返回"
    name="button2">
    </td>
    <P><asp:label id="strStatus" runat="server" Width="500px" Font-Names="宋体" Font-Bold="True" Font-Size="9pt"
    BorderStyle="None" BorderColor="White"></asp:label></P>
    </tr>
    ----------------------------------------------------------------------------------
    后台获取并写入数据库:
    -------------------
    #region 上传新附件

    ArrayList al =new ArrayList();
    for(int i = 0;i<Request.Form.Count;i++)
    {
    if(Request.Form.Keys[i].ToString().Length>4)
    {

    if(Request.Form.Keys[i].ToString().Substring(0,4)=="fjsm")
    {

    al.Add(Request.Form[i].ToString());

    }
    }
    } ///'遍历File表单元素
    HttpFileCollection files  = HttpContext.Current.Request.Files; /// '状态信息
    System.Text.StringBuilder strMsg = new System.Text.StringBuilder();
    string fileName,fileSearchName, fileExtension,strFJXH1,strFJBT1,strDirectory,strSearchDirectory;
    try
    {
    for(int iFile = 0; iFile < files.Count; iFile++)
    {
    ///'检查文件扩展名字
    HttpPostedFile postedFile = files[iFile];

    fileName = System.IO.Path.GetFileName(postedFile.FileName);
    fileSearchName=fileName; fileExtension = System.IO.Path.GetExtension(fileName);
    strFJXH1 =(new AppDataCMP.DocumentManageCMP()).GetNewID("OA_DA_FJ","FJXH").ToString();
    fileName="gxb_"+SystemManage.SystemUserManage.GetUserID(Session).ToString()+"_"+strFJXH1+fileExtension;
    fileSearchName=fileSearchName.Replace(fileExtension,"")+"["+strFJXH1+"]"+fileExtension;
    //生成目录
    strDirectory=(new AppDataCMP.DocumentManageCMP()).GetDocumentAtthfilesUpLoadDirectory(System.Web.HttpContext.Current.Request.MapPath("DocumentAtthfiles/"));
    strSearchDirectory=(new AppDataCMP.DocumentManageCMP()).GetDocumentSearchUpLoadDirectory(System.Configuration.ConfigurationSettings.AppSettings["FilePath"],this.txtFBFL.Text+@"\");
    //寻找附件标题
    strFJBT1=al[iFile].ToString();

    //增加到数据库
    SortedList temp = new SortedList(); temp.Add("FJXH",strFJXH1);
    temp.Add("DAXH",this.txtDAXH.Text);
    temp.Add("FJBT",strFJBT1);
    temp.Add("CDLJ","documentatthfiles"+@"/"+strDirectory.Substring(strDirectory.Length-8,8)+@"/"+fileName);
    //temp.Add("CCGS",null)
    //temp.Add("XJCX",null);
    AppDataCMP.DocumentManageCMP dm = new AppDataCMP.DocumentManageCMP();
    dm.Open();
    dm.AddNewDocumentAtthfiles(temp);
    dm.Close();

    //上传附件
    postedFile.SaveAs(strDirectory +@"\"+ fileName);
    postedFile.SaveAs(strSearchDirectory+@"\"+ fileSearchName);
    }

    }
    catch(System.Exception Ex)
    {
    strStatus.Text = Ex.Message;

    }
      

  8.   

    你的代码中哪一个对象等价于楼主的DropDownList 类型的那个控件?能否说明?
      

  9.   

    看一下原理就行
    就是用上面的js增加控件
    用Request.Form获取表单提交的东西。
    -------------------------------------
    老大,是你叫我们写程序重在思想的吧?如果你非要给楼主答案,你可以将上面的代码套用一下就行了。
      

  10.   

    很简单的,你就用Page.ispostback属性就可以了.
    jf!!
      

  11.   

    to:codeangel(http://www.wSoft.Net)我只是问你打算提醒楼主“套用哪一个控件”? 并不求对错,只要你说出一个对象名称来就行了。甚至不用套用,只要你点出哪一个控件的控制方式相当于楼主需要的那个 DropDwonList 的方式来就行。我确实只是简单地用几秒钟扫了一下你的代码代码,所以我并不敢说你的代码是否能够套用,我只是觉得你的答案很容易被理解为凑行数,所以我帮你点睛一下嘛。我确实相信这对你也会有好处。
    其实至于楼上那样的回复,一般我都不会多事。我相信那纯粹是随便仍一句某个牛人说过“此句时髦”的话而已,并没有结合楼主的问题。