I have a webpage: Menu.aspx, where I have the following controls of relevance:
In my Edit.aspx page, I have a cancel button, which redirects the user back to the Menu page
What I would like to do is when my user clicks on the hyperlink to go to the Edit page,index of the DropDownList is preserved in a query string In my Menu.aspx page I have the following aspx code, but I am not sure how to proceed
<asp:HyperLink
ID="lnkEdit"
NavigateUrl='<%# "Edit.aspx?" + Eval("UserID") + ...not sure... %>'
</asp:HyperLink>
<asp:DropDownList
ID="myDropDown"
...some <asp:ListItems/>
</asp:DropDownList>
EDIT: Clarified why Im using NavigateURL. Because my query string already does an Eval to determine the user ID.
I would use a LinkButton control with a server-side OnClick event.
<asp:LinkButton ID="lbtn1" runat="server" OnClick="lbtn1_Click"
CommandArgument='<%#Eval("UserID") %>' />
Server side method:
public void lbtn1_Click(object sender, EventArgs e)
{
LinkButton lbtn = (LinkButton)sender;
string userID = lbtn.CommandArgument;
string dropDownValue = myDropDown.SelectedValue;
string navigateUrl = string.Format("Edit.aspx?userid={0}&dropdown={1}",
userID, dropDownValue);
Response.Redirect(navigateUrl);
}
EDIT: As Royi Namir points out below, javascript is a better option if you can use that. This creates an unnecessary round trip to the server.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With