Page.RegisterStartupScript("pringGP", "<script>" + ClientScript + "</script>");此脚本在一个页面只能运行一次,但是我想每次点击按钮都能运行一次,但是此方法不行,不知道怎么该,或者还有其他的方法和函数吗?请赐教,比较急。

解决方案 »

  1.   

    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "scriptBlock", "function ok() { alert('funny'); }", true);Page.ClientScript.RegisterStartupScript(this.GetType(), "startup", "ok();", true);
      

  2.   

    要不这么说吧。
    Page_Load里:
    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "scriptBlock", "function ok() { alert('funny'); }", true); 然后
    <asp:Button ID="***" runat="server" OnCientClick="ok();return false;" />如果是html button
    <input type="button" onclick="ok();" value="***" />
      

  3.   

    按你的:
    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "scriptBlock", ClientScript, true); 
      

  4.   

    YourButton.Attributes["onclick"] = ClientScript + ";return false;";
      

  5.   

    我是GridView里的asp:ButtonField 的属性按钮,当我点击时弹出一个对话框就是利用(Page.RegisterStartupScript("pringGP", "<script>" + ClientScript + "</script>");), 每次点击时里面的数据可能不一样,但是好像这个脚本只能运行一次,如果数据改变的话,再点击按钮,页面显示数据就没有变化,其实数据库已经变了
      

  6.   

    这得看你这个ClientScript在做什么动作了,和Page.RegisterStartupScript没有直接关系。
    把神秘的ClientScript贴上来吧:-)
      

  7.   


     protected void GridViewRelation_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            CostManagement Cost = new CostManagement();
            if (e.CommandName.ToUpper() == "HISTORYRECORD")
            {
                 int i = Convert.ToInt32(e.CommandArgument);
                 string cardId = GridViewRelation.Rows[i].Cells[5].Text;
                 string carno = GridViewRelation.Rows[i].Cells[4].Text;
                string url = "FrmAtrriHistory.aspx?cardId=" + cardId + "&carno=" + carno;
                string ClientScript = "window.showModalDialog('" + url + "','history','dialogWidth:800px;dialogHeight:600px;dialogLeft:200px;dialogTop:200px;center:yes; help:yes;resizable:yes;status:yes')";
                Page.RegisterStartupScript("pringGP", "<script>" + ClientScript + "</script>");
            }
        }
      

  8.   

    经过我其他的操作,数据库里的数据就会改变,再一次点击datagrid的按钮,弹出的页面里的显示数据实际上已经改变了,但是还和我改变数据之前的一样。我感觉是当改变数据后再一次点击按钮,没有执行弹出页面里的载入方法。
      

  9.   

    YourButton.Attributes["onclick"] = ClientScript + ";return false;";这个要写在 RowDataBound 事件处理方法中,并且你要首先使用 FindControl 找到并赋值给YourButton。同样,使用 FindControl 找到数据并赋值给 url。可能到“GridViewRelation.Rows[i].Cells[5].”这类代码,我就觉得你很累了。如果你在我这里写程序,我会告诉你要记住,GridViewRelation的列顺序是随时可能改变的。
      

  10.   

    CommandArgument传的是什么呀?如上所说string cardId = GridViewRelation.Rows[i].Cells[5].Text;这个转换过程显得好累。
      

  11.   

    哦,明白了,原来是ButtonField,自动传进来行索引是吧?
      

  12.   

    你的问题是不是FrmAtrriHistory.aspx这个页面里更新数据以后,主页面刷新的问题啊?
      

  13.   

    加上红色部分:
    string ClientScript = "window.showModalDialog('" + url + "','history','dialogWidth:800px;dialogHeight:600px;dialogLeft:200px;dialogTop:200px;center:yes; help:yes;resizable:yes;status:yes');location.reload();";
      

  14.   

    我设置断点跟踪了一下,当在主页面上时,点击gridview上的按钮,可以执行弹出页面里的方法,但在此页面上有个按钮可以修改数据,修改后我再点击gridview上的按钮时,设置的断点没有执行,弹出页面上的列表数据就也没变化。在主页面刷新也没用,除非重新运行程序才可以看到变化后的数据,但是再改变数据后再看的话就又不行了,又回到了我所说的问题。
      

  15.   

    我特意做了个类似的东西,有编辑功能的GridView,加上楼主写的showModalDialog,没有碰到这种问题。和楼主目前show的代码应该是没关系。是别的问题。
      

  16.   

    别加了,那是以为是在showModalDialog弹出的页面上修改数据的情况。
      

  17.   


    当然了。FrmAtrriHistory.aspx是不是显示最新数据啊?
      

  18.   

    那肯定就是FrmAtrriHistory.aspx同学工作不认真了!他凭什么不从数据库读取最新数据?
      

  19.   

    不是,弹出页面的载入方法就是从数据库里取所有的记录,我不是说了吗?这个弹出页面只是第一次执行载入方法,再点击gridview上的按钮是这个弹出页面的初始方法就不再执行了,我就是想问这个问题是问什么?