开发者

Referencing variables from C# in ASP.NET

开发者 https://www.devze.com 2023-02-10 16:22 出处:网络
I am trying to use QueryStrings from my C# file in my ASPX file: <asp:Button ID=\"LinkButtonDetails\" runat=\"server\" Text=\"DETAILS\"

I am trying to use QueryStrings from my C# file in my ASPX file:

<asp:Button ID="LinkButtonDetails" runat="server" Text="DETAILS" 
PostBackUrl='<%# string.Format("~/projectdetails.aspx?guid=<%= id%>
&name=<%= name%>
&role=<%= company_role%>
&member=<%= mem_id%>
&company={0}
&project={1}&id={2}", Eval("CompanyID"), Eval("ProjectName"), Ev开发者_C百科al("ProjectID")) %>' />

The values are not appended to the url, what am I doing wrong? Thanks for your help!


Assuming that id, name, company_role, mem_id are fields or properties of your page(control) I'd recomend you to do following:

In aspx markup file write:

<asp:Button ID="LinkButtonDetails" runat="server" Text="DETAILS" PostBackUrl='<%# GenerateLink(Eval("CompanyID"), Eval("ProjectName"), Eval("ProjectID")) %>' />

And in the cs file write:

protected string GenerateLink(object companyId, object projectName, object projectId)
{
    return string.Format("~/projectdetails.aspx?guid={0}&name={1}&role={2}&member={3}&company={4}&project={5}&id={6}", id, name, company_role, mem_id, companyId, projectName, projectId);
}

Also don't forget to call DataBind.

P.S. You may also need to encode your query string arguments using HttpUtility.UrlEncode()


On page load call

Page.DataBind();
0

精彩评论

暂无评论...
验证码 换一张
取 消