views:

35

answers:

3

hi, when asp.net output a page ,I want to add some same parameters for all links() in this page How I can do it ?

somesite.com/page.aspx => somesite.com/page.aspx?same=value

somesite.com/?anyp=hevalue => somesite.com/?anyp=hevalue&same=value

auto add same=value

+1  A: 

If they are all server controls such as <asp:LinkButton> then you can walk the Page.Controls collection and modify them. You would probably have much better luck doing this on the client side, however. jQuery is great for such things.

Dave Swersky
No,I am not use any server controls, is it better on the client side do this ?
xgluxv
Yes and no if you use jquery it will be easy to do, but might break the application when javascript it turned off by the end user. about 2-5% of users have javascript disabled.
TheAlbear
That's true, with a jQuery-only solution you'd cut out anyone not running javascript.
Dave Swersky
A: 

You can also do some coding on the .aspx page

<a href='<%#"http://localhost/MyPage.aspx?RoomID=" + txtNumber.Text %>'>RoomID</a>
hallie
The workload is too bigggg
xgluxv
+2  A: 

With jQuery:

//adding the same query string parm to all links
var parameter = "&parameter=value";
$('a').each(function(){
  var href = $(this).attr('href');
  $(this).attr('href', href + parameter);
});
Eric
xgluxv
I edited my answer - this should do it if you're not using any server controls. I haven't tested this, but I think it's pretty close :)
Eric