按钮单击事件C#ASP.NET HTML5后将位置传递给代码 [英] Passing location into code behind after button click event C# ASP.NET HTML5

查看:88
本文介绍了按钮单击事件C#ASP.NET HTML5后将位置传递给代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在互联网上尝试了这么多资源,让当前用户的经纬度被传递到我的C#asp.net网站后面的代码中,但仍然没有找到可行的解决方案。



所以基本上当用户点击我网站上的搜索按钮时,我必须得到他当前的GEO位置并将其传递给后面的代码。请记住,这意味着我已经有一个名为Submit_Search的点击事件。



为了那里我计划计算距离,但如果我能得到这些2在按钮事件后面的代码中的变量,我将永远感激!



我尝试在网站管理员的标题中添加javascript。我试过在设计视图中添加一个带有隐藏的asp字段的javascript。我试过切换它并将JS移动到外部文件并引用它。但是这些似乎都不适用于visual studio 2014和HTML5(使用带有网站主应用程序的网页表单)。



请有人协助吗?



提前付款。



我的尝试:



我用runat =Server尝试过SAp隐藏字段。

带有GetElementbyID的javascript(变量的标签ID),然后为其赋值。

我尝试使用代码中的javascript构建一个字符串,然后在按钮点击时运行它。

我试过在代码后面调用javascript。

到目前为止,这些都没有。

So I have tried so many resources on the internet to get the current users latitude and longitude to be passed into the code behind of my C# asp.net website and still have not found a working solution.

So basically when a user clicks the search button on my website, I have to get his current GEO location and pass that through to the code behind. Please keep in mind that this means I already have a click event called "Submit_Search".

For there I plan on calculating distance, but if I can just get these 2 variables in code behind on the button event, I'd be ever grateful!.

I have tried adding the javascript in the header of the site master. I have tried just adding the javascript in the design view with a hidden asp field. I have tried switching it around and moving the JS to an external file and referencing it. But none of these seem to work in visual studio 2014 and HTML5 (using web forms with site master application).

Please, can someone assist?

Thanx in advance.

What I have tried:

I have tried SAp hidden field with runat="Server".
A javascript with GetElementbyID("Tag ID of a variable") and then assigning a value to it.
I have tried building a string with the javascript in code behind and then running it on button click.
I have tried just calling the javascript in code behind.
None of these have worked so far.

推荐答案

我看不到你的标记,所以这都是假设:



隐藏字段(这是最简单的解决方案)必须在提交的表单中。如果您已在服务器上运行,则该字段的ID将更改。这就是asp.net处理避免重复的方式。



您可以使用控件的asp.net的ClientID来获取真实的id,或者你可以使用jQuery选择器,用于获取id以id结尾的元素。另一种方法是在页面加载时将控件设置为静态id(服务器端)。这意味着asp.net不会更改id。



一旦你拥有了id并设置了控件的值,你就可以读取它的服务器 - 在页面上加载(检查表单IsPostBack属性以查看它是否是新加载或表单提交加载)。



希望有帮助^ _ ^

Andy
I can't see your markup so this is all hypothetical:

The hidden field (which would be the easiest solution) must be within the form being submitted. If you have run at server then the id of the field will change. This is how asp.net handles avoiding duplicates.

You can use the asp.net's "ClientID" of the control to get the true id, or you can use a jQuery selector to get elements where the id ends with your id. Another way is to set the control to static id (server side) on page load. That will mean that the id will not be changed by asp.net.

Once you have the id and set the value of the control, you can read it server-side on page load (check the forms "IsPostBack" property to see if it's a new load or a form submit load).

Hope that helps ^_^
Andy


这篇关于按钮单击事件C#ASP.NET HTML5后将位置传递给代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆