English 中文(简体)
从编码背后,错误
原标题:passing arguments to javascript function from code-behind , error

载于以下法典:

    string func = "showSuccessMessage("+name+");";
    ClientScript.RegisterStartupScript(this.GetType(), "success", func, true);

in a js file :

   function showSuccessMessage(user)
   {
        $("#box").dialog({
            title:"User Registration",
            html: user.toString() + " Successfully Registered", 
            modal: true,
            buttons: {
                   Ok: function () {
                    $(this).dialog("close");
                    var s = "../Pages/main.aspx";                
                    window.location = s;
                   }
        }
   });
 } // end function 

在试图通过无任何论据的重罪时,每件事都会被罚款。

一、试图将论点纳入显示从浏览器中产生错误的职能

不详 错误:john没有定义

(john being the value of name) now i m guessing the problem occurs because the way the function is registered it can t distinguish between a the variable and the value , so it is a non-defined type john

因此,问题是:

如何从编码背后向javascript功能提出论据

thanks in advance eran.

btw similar question : showing something similar to what iv e attempted

similar question

最佳回答

你们撰写这一文件的方式,就像通过john,将其作为一个变量,而不是一个缩略语。 它喜欢援引

showSuccessMessage(john); // what you re doing in js
showSuccessMessage( john ); // what you need

更正

string func = "showSuccessMessage( "+name+" );"; 
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签