简体   繁体   English

将C#字符串发送到aspx.NET页面

[英]Sending a C# string to aspx.NET page

I have a C# string that contains the answer to the question "May we contact?" 我有一个C#字符串,其中包含问题“我们可以联系吗?”的答案。 How do I transfer that to our aspx webpage? 如何将其转移到我们的aspx网页? The c# string is in the code behind page. c#字符串在页面后面的代码中。

If the string is a protected (at least) property on the page then it can be accessed in the page's markup. 如果字符串是页面上的(至少) protected属性,则可以在页面的标记中访问它。 So the string would be something like this at the class level: 因此,字符串在类级别将是这样的:

protected string MyString { get; set; }

And in the page markup you can access its value: 在页面标记中,您可以访问其值:

<%= MyString %>

If you want to send the string to another page besides the code-behind it lives in, then use a query string entry to pass it to the URL you are redirecting to. 如果您要将字符串发送到除其背后的代码之外的其他页面,请使用查询字符串条目将其传递到您重定向到的URL。 If you want the current page to access the C# string, then make the string a protected property so the page can use it an embedded code block. 如果希望当前页面访问C#字符串,则将该字符串设置为protected属性,以便该页面可以将其用作嵌入式代码块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM