Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何获取在按钮按下事件期间创建的信息以显示在html页面上?_C#_Asp.net_.net_Html - Fatal编程技术网

C# 如何获取在按钮按下事件期间创建的信息以显示在html页面上?

C# 如何获取在按钮按下事件期间创建的信息以显示在html页面上?,c#,asp.net,.net,html,C#,Asp.net,.net,Html,我正在使用visual studio 2010制作一个asp.net应用程序。我有一个文本字段和按钮,用于调用文本字段中字符串的方法 Enter your address here: <asp:TextBox ID="tb_address" runat="server" ></asp:TextBox> <asp:Button Text="Submit" runat="server" onclick="GetLatLong" ></asp:Button&g

我正在使用visual studio 2010制作一个asp.net应用程序。我有一个文本字段和按钮,用于调用文本字段中字符串的方法

Enter your address here: <asp:TextBox ID="tb_address" runat="server" ></asp:TextBox>
<asp:Button Text="Submit" runat="server" onclick="GetLatLong" ></asp:Button>
如何让我的lat和lon字符串显示在html页面上?

使用
s

<asp:Label ID="lblLat" runat="server" />
<asp:Label ID="lblLong" runat="server" />

String lat = xDoc.SelectSingleNode("/GeocodeResponse/result/geometry/location/lat").InnerText;
String lon = xDoc.SelectSingleNode("/GeocodeResponse/result/geometry/location/lng").InnerText;
lblLat.Text = lat;
lblLong.Text = lon;

字符串lat=xDoc.SelectSingleNode(“/GeocodeResponse/result/geometry/location/lat”).InnerText;
字符串lon=xDoc.SelectSingleNode(“/GeocodeResponse/result/geometry/location/lng”).InnerText;
lblLat.Text=lat;
lblLong.Text=lon;

您必须创建用于显示结果的控件(您可以在设计模式下将它们添加到表单中,也可以在单击事件处理程序上动态添加它们)。假设asp:Labels,然后将结果值指定给这些标签

Label result1 = new Label();
result1.Text = lat;
this.Controls.Add(result1);

在你的代码中有这个

<asp:Label ID='result1' runat='server' />

可以包含一些
Literal
控件(或
Label
控件,或任意数量的其他页面元素)来保存值。控件将如下所示:

<asp:Literal runat="server" ID="LatitudeOutput" />
<asp:Literal runat="server" ID="LongitudeOutput" />

在很多情况下,我个人更喜欢
Literal
控件,因为它们不会带来任何额外的标记<例如,代码>标签控件被包装在
span
标记中。但是,与许多事情一样,有很多方法可以做到这一点。

您必须在您的aspx页面上创建标签控件。将其添加到您希望显示lng和lat的aspx页面

<asp:Label ID="lblLat" runat="server" />
<asp:Label ID="lblLng" runat="server" />

您正在将标签文本设置为通过SelectSingleNode调用获得的值。

如果您只执行一个xpath查询(一级以上),则可以保存一些位。我不确定您在说什么@abatishchev.No problem@GrahamCarling,HTH.exec xpath once:
“/GeocodeResponse/result/geometry/location/
然后读取子项。不是两次-这是我的观点我明白你现在说的@abatishchev。我刚刚讨论了OP的问题,如何在页面上显示字符串。
<asp:Literal runat="server" ID="LatitudeOutput" />
<asp:Literal runat="server" ID="LongitudeOutput" />
String lat = xDoc.SelectSingleNode("/GeocodeResponse/result/geometry/location/lat").InnerText;
String lon = xDoc.SelectSingleNode("/GeocodeResponse/result/geometry/location/lng").InnerText;
LatitudeOutput.Text = lat;
LatitudeOutput.Text = lon;
<asp:Label ID="lblLat" runat="server" />
<asp:Label ID="lblLng" runat="server" />
lblLat.Text = xDoc.SelectSingleNode("/GeocodeResponse/result/geometry/location/lat").InnerText;
lblLng.Text = xDoc.SelectSingleNode("/GeocodeResponse/result/geometry/location/lng").InnerText;