通过Querystring传递用户输入值而不需要代码

时间:2022-02-23 15:12:17

I'm trying to generate a report through my site.

我正在尝试通过我的网站生成报告。

Default.aspx has a dropdownlist and 2 textboxes. The report (which is generated on a different page) must use all of the values from these 3 controls in the sql query used to collect the data from SQL Server.

Default.aspx有一个下拉列表和2个文本框。报告(在不同页面上生成)必须使用用于从SQL Server收集数据的sql查询中的这3个控件的所有值。

Concept
The user can leave all 3 fields with their default values, or change any of them. After deciding what values the user wants to see a report on, they can click a HyperLink control to open to the report page in a new tab.

概念用户可以将所有3个字段保留其默认值,或更改其中任何一个。在确定用户想要查看报告的值后,他们可以单击HyperLink控件以在新选项卡中打开报告页面。

The value from the DropDownList is passed through to Report.aspx via a Session variable set on SelectedIndexChanged. Report.aspx reads this and should read the Text values for the 2 textboxes as well.

DropDownList中的值通过SelectedIndexChanged上设置的Session变量传递给Report.aspx。 Report.aspx读取此内容并应读取2个文本框的Text值。

Problem
I can't figure out how to send the values of the TextBoxes through to Report.aspx. I thought of doing the following:

问题我无法弄清楚如何将TextBoxes的值发送到Report.aspx。我想到了以下几点:

<asp:HyperLink runat="server" id="lnkReport"
  NavigateUrl="Report.aspx?fromdate=<%# Eval('txtFromDate.Text') %>&todate=<%# Eval('txtToDate.Text') %>"
  target="_blank" Text="Generate Report"></asp:HyperLink>

I'm not sure this would work though, as Eval typically requires a parent control to be data bound - as far as I'm aware anyway.

我不确定这会起作用,因为Eval通常需要一个父控件来进行数据绑定 - 据我所知。

Any suggestions will be greatly appreciated

任何建议将不胜感激

3 个解决方案

#1


0  

Using jQuery or Javascript You could just call a a client side function to get the values from the form elements, construct the url and open a new window?

使用jQuery或Javascript你可以调用一个客户端函数来从表单元素中获取值,构造url并打开一个新窗口?

#2


0  

After I asked this question, I remembered that the Dropdownlist and textboxes are used to bind a GridView on Default.aspx and I used this to my advantage here.

在我提出这个问题后,我记得Dropdownlist和文本框用于绑定Default.aspx上的GridView,我在这里使用了这个优势。

I know that one way or another, the GridView absolutely has to be bound before I click to generate the report, so I set session variables there to store the information that the report requires.

我知道,无论如何,在我点击生成报告之前必须绑定GridView,因此我在那里设置会话变量来存储报告所需的信息。

Dim db As New Database

Dim sql As String = "select * from users where userid = @id and dateregistered between @fromdate and @todate"

Dim args As New List(Of SqlParameter)
args.Add(New SqlParameter("@id", ddlUsers.SelectedItem.Value))
args.Add(New SqlParameter("@fromdate", txtFromDate.Text))
args.Add(New SqlParameter("@todate", txtToDate.Text))

gvItems.DataSource = db.GetDataReader(sql, args.ToArray())
dvItems.DataBind()

Session("userid") = ddlUsers.SelectedItem.Value
Session("fromdate") = txtFromDate.Text
Session("todate") = txtToDate.Text

#3


0  

Instead of using a HyperLink, you could use a link button to do some cross page posting.

您可以使用链接按钮进行跨页面发布,而不是使用HyperLink。

<asp:LinkButton runat="server" id="lnkReport"
  NavigateUrl="~/Report.aspx"
  target="_blank" Text="Generate Report"></asp:LinkButton>

Then on Report.aspx.cs:

然后在Report.aspx.cs上:

Get the values from the Page.PreviousPage as follows:

从Page.PreviousPage获取值,如下所示:

DropDownList userid = (DropDownList)Page.PreviousPage.FindControl("ddlUsers");
TextBox fromdate = (TextBox)Page.PreviousPage.FindControl("fromdate");
TextBox todate = (TextBox)Page.PreviousPage.FindControl("todate");

Use these as you require in your reports page.

在报告页面中根据需要使用这些。

#1


0  

Using jQuery or Javascript You could just call a a client side function to get the values from the form elements, construct the url and open a new window?

使用jQuery或Javascript你可以调用一个客户端函数来从表单元素中获取值,构造url并打开一个新窗口?

#2


0  

After I asked this question, I remembered that the Dropdownlist and textboxes are used to bind a GridView on Default.aspx and I used this to my advantage here.

在我提出这个问题后,我记得Dropdownlist和文本框用于绑定Default.aspx上的GridView,我在这里使用了这个优势。

I know that one way or another, the GridView absolutely has to be bound before I click to generate the report, so I set session variables there to store the information that the report requires.

我知道,无论如何,在我点击生成报告之前必须绑定GridView,因此我在那里设置会话变量来存储报告所需的信息。

Dim db As New Database

Dim sql As String = "select * from users where userid = @id and dateregistered between @fromdate and @todate"

Dim args As New List(Of SqlParameter)
args.Add(New SqlParameter("@id", ddlUsers.SelectedItem.Value))
args.Add(New SqlParameter("@fromdate", txtFromDate.Text))
args.Add(New SqlParameter("@todate", txtToDate.Text))

gvItems.DataSource = db.GetDataReader(sql, args.ToArray())
dvItems.DataBind()

Session("userid") = ddlUsers.SelectedItem.Value
Session("fromdate") = txtFromDate.Text
Session("todate") = txtToDate.Text

#3


0  

Instead of using a HyperLink, you could use a link button to do some cross page posting.

您可以使用链接按钮进行跨页面发布,而不是使用HyperLink。

<asp:LinkButton runat="server" id="lnkReport"
  NavigateUrl="~/Report.aspx"
  target="_blank" Text="Generate Report"></asp:LinkButton>

Then on Report.aspx.cs:

然后在Report.aspx.cs上:

Get the values from the Page.PreviousPage as follows:

从Page.PreviousPage获取值,如下所示:

DropDownList userid = (DropDownList)Page.PreviousPage.FindControl("ddlUsers");
TextBox fromdate = (TextBox)Page.PreviousPage.FindControl("fromdate");
TextBox todate = (TextBox)Page.PreviousPage.FindControl("todate");

Use these as you require in your reports page.

在报告页面中根据需要使用这些。