MiziaQ
MiziaQ

Reputation: 271

Referencing variables from C# in ASP.NET

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"), Eval("ProjectID")) %>' />

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

Upvotes: 0

Views: 221

Answers (2)

santosh singh
santosh singh

Reputation: 28642

On page load call

Page.DataBind();

Upvotes: 0

Oleg Rudckivsky
Oleg Rudckivsky

Reputation: 930

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()

Upvotes: 2

Related Questions