我写了下面的代码,它将单选按钮值和复选框值转移到另一个HTML表单,但我根本没有找到解决方案来将单选按钮或复选框转移到另一个表单,而不仅仅是所选值。
我想要的单选按钮转移到另一种形式,如下面的值。
Dim Gender As String = RadioButton1.SelectedValue
Response.Redirect("PrintPreview.aspx?"&Gender=" + Gender)
Label1.Text = Request.QueryString("Gender")代码仅返回单选按钮值
请指教
发布于 2021-11-06 15:24:53
好的,第一件事,也是这里最重要的一件事是,当你执行response.Redirect时?
It STOPS code running in the current page.
No code AFTER the Response.Redirect will run
All variables, and code and ALL values for the current page are destroyed!因此,您不能(通常)编写在response.Redirect之后运行的代码。
所以,假设我们有这样的标记:
<br />
<asp:RadioButtonList ID="RadioButtonList1" runat="server"
Font-Size="Larger" RepeatDirection="Horizontal">
<asp:ListItem>Yes</asp:ListItem>
<asp:ListItem>No</asp:ListItem>
</asp:RadioButtonList>
<br />
<asp:Button ID="Button1" runat="server" Text="Done" />我们的页面现在看起来像这样:

现在,我们要跳到第2页。
因此,我们的代码可以在我们的Test1页面中这样写。
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Gender As String = RadioButtonList1.SelectedItem.Text
Response.Redirect("Test2.aspx?&Gender=" & Gender)
' code AFTER above line WILL NOT run!!!!
End Sub所以,我们不能在response.Redirect之后有代码。
再读一遍,读5遍:
when the response.Redirect is used, then the current page code STOPS,
and ALL values, and even your code variables are DESTROYED!!! This is not much
different then when you get to the end of a subroutine - when you exit, then all
values and things in that subroutine are "gone", and "do not exist".同样的道理也适用于你的网页-使用Response.Redirect意味着停止代码,转移到另一个页面。
现在,上面将跳转到页面Test2,我们希望获取我们传递的值,并执行以下操作:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
' save a label on this page to the passed choice
Label1.Text = Request.QueryString("Gender")
End If
End Sub此外,请注意close您传递给Response.Redirect的字符串的语法也是不正确的。
https://stackoverflow.com/questions/69864434
复制相似问题