嗨我的图像按钮有问题,我必须按两次才能查看地图。下面是我的脚本。如果您有任何建议,我会很高兴并感谢您的帮助
Protected Sub ImageButton4_Click(sender As Object, e As ImageClickEventArgs) Handles ImageButton4.Click
Dim txturl1 As String = "https://www.google.com/maps?q=" + txtsrcNo.Text.Trim + ",+" + txtSrcStName.Text.Trim + ",+" + txtSrcCity.Text.Trim + ",+" + txtSrcCountry.Text.Trim
ImageButton4.Attributes.Add("onclick", "window.open('" + txturl1 + "',null,'height=600, width=600,status= no, resizable= yes, scrollbars=no, toolbar=no,location=no,menubar=no ');")
End Sub
答案 0 :(得分:2)
您只需在按下按钮时设置onclick
代码。
onclick
中指定的任何代码,在用户单击按钮时在客户端(浏览器)上运行。您必须从服务器端设置onclick
代码(就像您正在做的那样),但您必须在有人按下按钮之前设置它。
现在,第一次按下它时,设置onclick
代码,第二次按下它,onclick
代码运行,在客户端(浏览器)。
移动你的行:
ImageButton4.Attributes.Add("onclick", "window.open('" + txturl1 + "',null,'height=600, width=600,status= no, resizable= yes, scrollbars=no, toolbar=no,location=no,menubar=no ');")
要使用form_load或等效内容,以便在按下按钮之前设置onclick
代码。
答案 1 :(得分:0)
第一次按下ImageButton
时,只会添加下次点击按钮时触发的onclick
客户端事件。
您可以在Attributes.Add
事件中解决此问题客户端移动Page_init
,并使用javascript
收集用于在运行时查询Google地图的所有参数。
但我认为将ImageButton
置于UpdatePanel
并使用ScriptManager
来解决服务器端此问题更容易:
Dim strurl1 As String = "https://www.google.com/maps?q=" + txtsrcNo.Text.Trim + ",+" + txtSrcStName.Text.Trim + ",+" + txtSrcCity.Text.Trim + ",+" + txtSrcCountry.Text.Trim
ScriptManager.RegisterStartupScript(Me.Page, Me.Page.GetType, "openNewPage", "window.open('" + strurl1 + "',null,'height=600, width=600,status= no, resizable= yes, scrollbars=no, toolbar=no,location=no,menubar=no ');", True)