vb.net 如何通过RegisterStartupScript传递2个参数?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16543667/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 13:35:28  来源:igfitidea点击:

How to pass 2 parameters through RegisterStartupScript?

javascriptvb.netregisterstartupscript

提问by migmig

I have a javascript function "initialize (latitude, longitude)" and when I click on my button I want to pass the value from my textbox to do something.

我有一个 javascript 函数“初始化(纬度,经度)”,当我点击我的按钮时,我想从我的文本框中传递值来做一些事情。

Protected Sub btnLat_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim latit As TextBox = formView.FindControl("nr_latitudeTextBox")
    Dim longit As TextBox = formView.FindControl("nr_longitudeTextBox")

    Page.ClientScript.RegisterStartupScript(Me.GetType(), "initialize", "initialize(" & latit.Text, longit.Text & ");", True)

End Sub

But when I try to do this I get the error

但是当我尝试这样做时,我得到了错误

Overload resolution failed because no accessible "RegisterStartupScript" accepts this number of arguments.

重载解析失败,因为没有可访问的“RegisterStartupScript”接受此数量的参数。

回答by Tim B James

You have just implemented the code wrongly. Change it to.

您刚刚错误地实现了代码。将其更改为。

If your initializefunction expects string variables then use the code;

如果您的initialize函数需要字符串变量,则使用代码;

Page.ClientScript.RegisterStartupScript(Me.GetType(), 
"initialize", "initialize('" & latit.Text & "','" & longit.Text & "');", True)

If initializeexpects integers then;

如果initialize期望整数然后;

Page.ClientScript.RegisterStartupScript(Me.GetType(), 
"initialize", "initialize(" & latit.Text & "," & longit.Text & ");", True)