Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi all! We have been experiencing an issue on site where threads have been missing the latest postings. The platform host Vanilla are working on this issue. A workaround that has been used by some is to navigate back from 1 to 10+ pages to re-sync the thread and this will then show the latest posts. Thanks, Mike.
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Passing dynamically added C# control values to querystring

  • 15-08-2006 10:29am
    #1
    Closed Accounts Posts: 80 ✭✭


    C# if possible. I have a webform which reads 30 values from a database and adds a RadioButton for each one to the form. The user is then invited to select a number of these values. This I have done and can do.

    What I have not done and need to program is the following: When the form is submitted redirect to another form with value pairs for the radiobutton selections in the querystring. Like so:

    newpage.aspx?Value1=0&Value2=1&Value3=0..........&Value30=1

    Where 1 is checked and 0 is unckecked, or something similar.

    I know this seems like a simple request but given that I have little c# experience and have inherited a project without much training I am having difficulty. I wont go into my attempts thus far but they have been significant and frustrating.

    Also can I control the names of the radiobuttons that are added they are being named _ctl0 to _ctl29?

    Finally and I hope I am not pushing my luck here, but how can I write events for the dynamically added controls?

    Any help is appreciated.
    Jim


Comments

  • Registered Users, Registered Users 2 Posts: 1,466 ✭✭✭Smoggy


    I presume its your code that is dynamically placing the controls and naming them ? well isn't it as simple as :

    1.) when the form is submitted reading the values out of the form , as you know the names going in.
    2.) when your dynamically making the controls , make the events hook up to your static sub to deal with the event.


  • Closed Accounts Posts: 80 ✭✭jimbozo


    1.) when the form is submitted reading the values out of the form , as you know the names going in.

    I dont know how many controls will be on the form, this may vary with the data. I had tried looping through the controls in the form checking for radiobuttons but was unable to see if they were checked as the code below failed when I try to access the Checked property of a Control object. note also an attempt to 'cast' the control to a radiobutton.
    
    foreach(Control  ctl in this.Controls  )
    {
    	if (ctl.GetType () == typeof(System.Web.UI.WebControls.RadioButton ))
    	{
    		i = i + 1;
    
    		if ((System.Web.UI.WebControls.RadioButton)ctl.Checked == true)
    		{
    			sQueryString = sQueryString + "/&Q" + i + "=1";
    		}
    		else
    		{
    			sQueryString = sQueryString + "/&Q" + i + "=0";
    		}
    	}
    }
    

    How would you fix/replace the code above?
    2.) when your dynamically making the controls , make the events hook up to your static sub to deal with the event.

    Thanks for this. I don't know how to do this but its is something I can lookup myself and is less important that the main issue.


  • Registered Users, Registered Users 2 Posts: 21,257 ✭✭✭✭Eoin


    I don't know if this is of any use, but check this out. As far as I know, Radio buttons don't appear in the Request.Form collection unless they have been checked. So, if you loop through the radio buttons, only the selected ones will appear.
    private void cmdSubmit_Click(object sender, System.EventArgs e)
    		{
    			foreach (string sVar in Request.Form)
    			{
    				Response.Write(sVar + "<BR>");
    			}
    		}
    

    By the way, checkboxes may be more appropriate if you can select multiple ones, rather than just one of the 30 or so


  • Closed Accounts Posts: 80 ✭✭jimbozo


    Eoin your code has done the job to perfection. Thank you. I also take your point that checkboxes would suit my purposes better.

    Cheers Jim


  • Registered Users, Registered Users 2 Posts: 21,257 ✭✭✭✭Eoin


    jimbozo wrote:
    Eoin your code has done the job to perfection. Thank you. I also take your point that checkboxes would suit my purposes better.

    Cheers Jim

    Brilliant stuff :)


  • Advertisement
Advertisement