开发者

linking to a radio button selection, asp.net c#

开发者 https://www.devze.com 2023-02-05 13:14 出处:网络
on the search for an answer to save the day. I have an \"articles\" page that holds a radiobutton list and a textarea. when the user selects a radio button, the text area is populated. now the users

on the search for an answer to save the day.

I have an "articles" page that holds a radiobutton list and a textarea. when the user selects a radio button, the text area is populated. now the users wants to be able to point to an article via a url link. (everything is dynamic and being pulled from a db source)

by using a 3 party tool i was able to grab the exact http request (below) that will link to the users' selection. the problem is the url is extremely long. is there another way to link to the radio button selection? that way i can just modify the query string 开发者_运维知识库to fit a specific format. thanks.

url to specfic radio button selection ---------------

http://localhost:60062/test/test_articles.aspx?__EVENTTARGET=ctl00%24MainContent%24RadioButtonList1%243&__EVENTARGUMENT=&__LASTFOCUS=&__VIEWSTATE=%2FwEPDwULLTEyMjYyNjEzNjcPZBYCZg9kFgICAw9kFgoCAQ8PZA8QFgFmFgEWAh4OUGFyYW1ldGVyVmFsdWUFFmh0dHA6Ly9sb2NhbGhvc3Q6NjAwNjIWAQIFZGQCBw9kFgICAw8PFgIeBFRleHQFATBkZAIJDzwrAA8CAA8WBB4LXyFEYXRhQm91bmRnHgtfIUl0ZW1Db3VudAIBZAoQFgAWABYAFgJmD2QWBmYPDxYCHgdWaXNpYmxlaGRkAgEPZBYCZg9kFgJmDxUBRUFzayB5b3VyIGtpZHMsICJ3aGF0IHdlcmUgdGhlIHRocmVlIGJlc3QgdGhpbmdzIHRoYXQgaGFwcGVuZWQgdG9kYXk%2FImQCAg8PFgIfBGhkZAILDw9kDxAWAWYWARYCHwBkFgECA2RkAhMPZBYIAgEPPCsADwIADxYEHwJnHwNmZAoQFgAWABYAZAIDDw9kDxAWAWYWARYCHwBlFgFmZGQCBQ8PZA8QFgFmFgEWAh8AZBYBAgNkZAIHDxAPFgIfAmdkEBUFAzQ0NAJmZgMzMzMBMwR0ZXN0FQUBOAE5AjE0AjE1AjMzFCsDBWdnZ2dnZGQYBAUUY3RsMDAkTmF2aWdhdGlvbk1lbnUPD2QFCVxBcnRpY2xlc2QFHl9fQ29udHJvbHNSZXF1aXJlUG9zdEJhY2tLZXlfXxYCBRhjdGwwMCRMb2dpblN0YXR1czEkY3RsMDEFGGN0bDAwJExvZ2luU3RhdHVzMSRjdGwwMwUSY3RsMDAkRGV0YWlsc1ZpZXcyDxQrAAdkZGRkZBYAAgFkBR5jdGwwMCRNYWluQ29udGVudCREZXRhaWxzVmlldzMPZ2Sn7TStsoTOeJn0xoyHzh41vo%2ByiD%2Ff2wmeKTuUwe9Ing%3D%3D&__EVENTVALIDATION=%2FwEWCQKVn9%2FvDwLh8vmTCALk7M7lDQKp6JekDwKm6JekDwK%2B6OenDwK%2B6OunDwK86OOnDwKxh73KAwOihkx44beFhpVDoerFt%2BLYkev3csEzPfS6PI4lPJbP&ctl00%24MainContent%24RadioButtonList1=15


No need to pass the ViewState around. What you need to do is put a simple parameter in the QueryString. Make the url something like:

http://www.mysite.com/MyPage.aspx?selected=1

Then look for that parameter in the codebehind and select the button server-side.

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        int selected;

        if (int.TryParse(Request.QueryString["selected"], out selected))
            RadioButtonList1.SelectedIndex = selected;
    }
}


Just use the anchor tag or one of the hyperlink controls. I'm not sure exactly what you did to get all the postback data but it sounds like you don't need any of that.

0

精彩评论

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