Note that there are some explanatory texts on larger screens.

plurals
  1. POmethod won't assign value to selectindex correctly, asp.net radiobuttonlist
    text
    copied!<p>I have a page with a radiobuttonlist and textarea. data is displayed dynamically within the textarea based on the user's selection. i also set up a OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged" to create a url that will allow users to reference their article (radio button selection). </p> <p>everything works except for cutting and pasting the created url (i.e. <a href="http://test.com/test.aspx?selected=3" rel="nofollow">http://test.com/test.aspx?selected=3</a>) into a new browser. the code keeps assigning the radiobuttonlist1.selectedindex to -1.</p> <p>so here's what i'm seeing in debug mode</p> <p><strong>Case 1</strong> when i cut and past the url in to a new browser <a href="http://test.com/test.aspx?selected=1" rel="nofollow">http://test.com/test.aspx?selected=1</a>, at the end of the page_load method code RadioButtonList1.SelectedIndex is equal to = -1. for some reason it's' not assigning the selectindex correctly.</p> <p><strong>Case 2</strong> when i select a radio button within the web page i launched, it skips the page_load code because <strong>post back is true</strong>. then creates a url within the RadioButtonList1_SelectedIndexChanged. then runs through the on page load method and hold the correct RadioButtonList1.SelectedIndex value at the end. </p> <p><strong>Case 3</strong> when i select a link within the webpage launched that is using pointing to <a href="http://test.com/test.aspx?selected=2" rel="nofollow">http://test.com/test.aspx?selected=2</a>, postback is false so it loops though the page_load code and successfully hold the correct RadioButtonList1.SelectedIndex value at the end.</p> <pre><code>protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { int selected; if (Request.QueryString["selected"] != null) { if (int.TryParse(Request.QueryString["selected"], out selected)) { RadioButtonList1.SelectedIndex = selected; RadioButtonList1.DataBind(); } } else { int firstart = 0; RadioButtonList1.SelectedIndex = firstart; } } } protected void SqlDataSource2_Selecting(object sender, SqlDataSourceSelectingEventArgs e) { } protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e) { try{ e.Command.Parameters["@URL_FK"].Value = Session["URL_PK"]; } catch (Exception ex) { } } protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e) { string strRedirect; strRedirect = "test.aspx?selected=" + RadioButtonList1.SelectedIndex; Response.Redirect(strRedirect); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload