Ram Singh
Ram Singh

Reputation: 6918

how to pass querystring in anchor tag?

I want to pass query string in anchor tag but facing some error i.e "server tag is not well formed". My code is:-

    <a href="EditUser.aspx?uid='<%# Eval("Userid") %>'" id="aa" runat="server" />

Upvotes: 0

Views: 13933

Answers (3)

Curtis
Curtis

Reputation: 103348

You cannot use code breaks with string text together for an attribute value for an element which is ran server side. Instead you can use String.Format() to form the same response, using single quotes.

<a href='<%# String.Format("EditUser.aspx?uid={0}", Eval("Userid")) %>' id="aa" runat="server" />

Upvotes: 0

Prashant Lakhlani
Prashant Lakhlani

Reputation: 5806

I generally use:

<a href='<%# Eval("Userid","EditUser.aspx?uid={0}") %>'>Text</a>/pre>

If you remove runat="server" and single quotes before and after eval expression, your code will also start working

Happy coding

Upvotes: 1

Waqas Raja
Waqas Raja

Reputation: 10872

Try this

<a href='<%# "EditUser.aspx?uid=" + Eval("Userid") %>' id="aa" runat="server" />

Upvotes: 0

Related Questions