从后面的代码调用javascript方法

我需要使用后面的代码中的参数调用JavaScript方法。

Javascript方法

 function changeControlSample(path) { $find('').set_UserControlPath(path); $find('').refresh(); }    
Updating...

页面背后的代码

 protected Consultation controlconsultation = new Consultation(); protected void Page_Load(object sender, EventArgs e) { PartialUpdatePanel7.UserControlPath = "Espace_Candidat/Consultation.ascx"; controlconsultation.imageinfo += controlconsultation_imageinfo; Session["controlconsultation"] = controlconsultation; } void controlconsultation_imageinfo(object sender, CommandEventArgs e) { PartialUpdatePanel7.UserControlPath = "Espace_Candidat/InfoEdition.ascx"; Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "changeControlSample('Espace_Candidat/InfoEdition.ascx')", true); } 

用户控件的代码

 public event CommandEventHandler imageinfo ; protected void Page_Load(object sender, EventArgs e) { Consultation current = (Consultation)Session["controlconsultation"]; imageinfo = current.imageinfo; } protected void Valider (object sender, CommandEventArgs e) { if (imageinfo != null) { string pageNumber = (string)e.CommandArgument; CommandEventArgs args = new CommandEventArgs("Control", pageNumber); imageinfo(this, args); } } 

即使我用另一个方法更改JavaScript方法,此调用也不起作用。

例如,如果我尝试

 Page.ClientScript.RegisterStartupScript (this.GetType(), "CallMyFunction", "alert('blabla');", true); 

我得到了相同的结果。

  1. 那么,我提出的错误是什么?
  2. 我该如何修复我的代码?

如果页面中有更新面板,则按此方式调用,

 ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), Guid.NewGuid().ToString(), @"", false); 

它没有更新面板,然后像这样调用

 Page.ClientScript.RegisterStartupScript(this.GetType(), "tabselect", ""); 

如果您希望使用后面的代码中的参数调用JavaScript方法,则可以使用此方法完成此操作

ClientScriptManager.RegisterStartupScript方法

请查看以下链接:

http://msdn.microsoft.com/en-us/library/z9h4dk8y(v=vs.110).aspx

希望这可以帮助。