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# ASP.NET中带有查询字符串的链接按钮_C#_Asp.net_Query String_Asplinkbutton - Fatal编程技术网

C# ASP.NET中带有查询字符串的链接按钮

C# ASP.NET中带有查询字符串的链接按钮,c#,asp.net,query-string,asplinkbutton,C#,Asp.net,Query String,Asplinkbutton,我有一个链接按钮如下 <asp:LinkButton ID="LinkButtonSearchClient" PostBackUrl="~/UI/clients.aspx" runat="server">Recherche </asp:LinkButton> <asp:HyperLink ID="HLink" runat="server" NavigateUrl='<%#"Mobiles_Details.aspx?ID=" + Eval("ID") %&

我有一个链接按钮如下

<asp:LinkButton ID="LinkButtonSearchClient" PostBackUrl="~/UI/clients.aspx" runat="server">Recherche </asp:LinkButton>
<asp:HyperLink ID="HLink" runat="server"  
NavigateUrl='<%#"Mobiles_Details.aspx?ID=" + Eval("ID") %>' Text='<%# 
Bind("Name") %>' Height="70px" Width="200px" Font-Bold="true" Font-
Size="10pt"  Font-Names="Times New Roman" />
试试这个

public string ID
    {
        get { Request.QueryString["id"]; }
    }
编辑:在您的页面加载设置您的回发url如下,访问服务器端的回发url

LinkButtonSearchClient.PostBackUrl = "~/UI/clients.aspx?id=" + this.ID;

要获取页面加载时的值(在backend.cs文件中),请执行以下操作:

或者您可能希望将id放入链接(在html中):


请参见下面的示例:

设计如下

<asp:LinkButton ID="LinkButtonSearchClient" PostBackUrl="~/UI/clients.aspx" runat="server">Recherche </asp:LinkButton>
<asp:HyperLink ID="HLink" runat="server"  
NavigateUrl='<%#"Mobiles_Details.aspx?ID=" + Eval("ID") %>' Text='<%# 
Bind("Name") %>' Height="70px" Width="200px" Font-Bold="true" Font-
Size="10pt"  Font-Names="Times New Roman" />

不确定你在问什么。请参考此链接:-@OldProgrammer你不明白我的问题吗?你可以在cs页面中使用代码,还是必须在aspx页面本身中设置url?使用response,redirect()方法,asp中的代码工作正常,我想试试这个方法Maku,OP在ID如何获取其值方面没有问题。他/她想从cs页面访问aspx的ID值page@Codeek是的,这正是我想做的,但是如何将id值输入到LinkButton中呢?这就是我在你的评论部分问你的。是否必须在aspx页面本身中设置url?是否可以在cs页面中设置?使用response.redirect()方法的源代码工作正常,但我想知道这样是否可能tooLinkbutton没有我知道的“NavigateUrl”属性。
<asp:LinkButton ID="LinkButtonSearchClient" runat="server" 
    NavigateUrl='<%# String.Format("~/UI/clients.aspx?id={0}", Eval("ID"))%>' 
    Text='Recherche'></asp:LinkButton>
<asp:HyperLink ID="HLink" runat="server"  
NavigateUrl='<%#"Mobiles_Details.aspx?ID=" + Eval("ID") %>' Text='<%# 
Bind("Name") %>' Height="70px" Width="200px" Font-Bold="true" Font-
Size="10pt"  Font-Names="Times New Roman" />
public partial class Mobiles_Details : System.Web.UI.Page
{

public string constr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

protected void Page_Load(object sender, EventArgs e)
{

    if (!Page.IsPostBack)
    {

        try
        {
            Session["UserID"] = "100";
            //int ID = 102;
            int ID = Convert.ToInt32(Request.QueryString["ID"].ToString());
            Session["Product_ID"] = ID;

            if (Session["UserID"] == null || Session["UserID"].ToString() == string.Empty)
            {
                Response.Redirect("Login.aspx", false);
            }
            else
            {

                if (ID != null)
                {   

                    DataTable dt = Load_Items_ID(Convert.ToInt32(Session["UserID"].ToString()), ID);

                    lbl_Name.Text = dt.Rows[0]["Name"].ToString();
                    lbl_Price.Text = dt.Rows[0]["Price"].ToString();
                    lbl_Details.Text = dt.Rows[0]["Details"].ToString();
                    img_Product.ImageUrl = dt.Rows[0]["image"].ToString();

                }
            }
        }
        catch (Exception ex)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "popup", "alert('An Error has been occured ');" + ex.ToString(), true);

        }
    }

}

public DataTable Load_Items_ID(int UserID, int ID)
{
    DataTable Returned_Value = new DataTable();

    using (SqlConnection con = new SqlConnection(constr))
    {
        using (SqlCommand cmd = new SqlCommand("SELECT * FROM  Products  where  UserID= " + UserID + " and  Status='False'  and  ID =" + ID))
        {
            using (SqlDataAdapter sda = new SqlDataAdapter())
            {
                cmd.Connection = con;
                sda.SelectCommand = cmd;
                using (DataTable dt = new DataTable())
                {
                    sda.Fill(Returned_Value);
                }
            }
        }
    }

    return Returned_Value;
}
}