在父页面上单击锚标记之前,我可以检查锚标记中的查询字符串吗?如果是这样,怎么样?

时间:2014-11-18 03:04:24

标签: c# asp.net webforms query-string

在我的应用程序FirstPage.aspx中,我使用转发器创建一系列链接:

<a href="MySecondPage.aspx?id=<%#DataBinder.Eval(Container.DataItem, "ValueID")%>">
<%#DataBinder.Eval(Container.DataItem, "ValueName")%></a>

通常,在MySecondPage.aspx的页面加载中,我会得到QueryString的值,如:

string OldID = Request.QueryString["id"];
num SkulloID = Convert.ToInt(SkulloID);

if(SkulloID > 5)
{
  Response.Write("Hello World");
}

而不是这个,我想要做的就是在FirstPage.aspx上以某种方式获取锚标记中的查询字符串的值来执行某些逻辑,就像MySecondPage.aspx的情况一样。这样的事情可能吗?

编辑测试解决方案

@CodingBiz我尝试了你提出的解决方案,我遇到了麻烦。这是我尝试过的。

Page_Load我添加了以下代码来设置链接按钮的CommandArgument

//Error: The name containder does not exist in the current context
lbnTestLink.CommandArgument = DataBinder.Eval(container.DataItem, "ValueID");

asp:LinkButton点击命令

MyID = DataBinder.Eval(container.DataItem, "ValueID");
using (SqlConnection conn2 = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnection"].ConnectionString))
{
    SqlCommand cmdzero = new SqlCommand(@"SELECT [num] FROM [My_Table] Where [ValueID] = @MyID AND [IsSubItem] = 1 AND [FiscalYear] = @FiscalYear", conn2);
    cmdzero.Parameters.AddWithValue("@MyID", MyID);
    cmdzero.Parameters.AddWithValue("@FiscalYear", strFiscalYear);
    conn2.Open();
    int countzero = (int)cmdzero.ExecuteScalar();
    int myArgument = countzero;
    if (MyID = myArgument)
    {
        strListLink = "FistPage.aspx";
    }
    else
    {
        strListLink = "SecondPage.aspx?id=<%#DataBinder.Eval(Container.DataItem, \"ValueID\")%>";
    }
}

我不明白这里应该设置查询字符串的位置。

0 个答案:

没有答案