RegisterStartupScript注册的东东是零时的,页面交后就没了
把RegisterStartupScript写在page_load的not ispostback外,每次提交就注册一把

解决方案 »

  1.   

    do it inside if (!IsPostBack) or use a ViewState variable, for example<script language="C#" runat=server>
    bool SetScript
    {
      get 
      {
    object o = ViewState["SetScript"];
    if (o==null)
    return true;
    else
    return (bool)o;
      }  set { ViewState["SetScript"] = value;}
    }void Page_Load(Object o, EventArgs e)
    {
      if (SetScript)
      {
    SetScript = false;
    //if (!IsPostBack)
    Page.RegisterStartupScript("Startup","<script>alert('hello');</" + "script>");
      }
    }</script>
    <form runat=server>
    <asp:Button id=btn runat=server Text="submit" />
    </form>
      

  2.   

    if the statement "RegisterStartupScript" is run in a loop,u may attention the folloing points:because of the first key has been registered,your seonde step must be not work.certainly,you could produce a random string as the key in the loop,so it will be solved.
      

  3.   

    其实前一次RegisterStartupScript提交后,留在客户端html脚本里,如果下一次提交时,你用RegisterStartupScript注册脚本,可将上次的注册脚本冲掉,如果你未用RegisterStartupScript注册脚本,则前一次的脚本还会运行,所以应该想个办法,在提交后,将注册的脚本运行后消掉,不知各位有何高招