Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2005
    Thanked 0 Times in 0 Posts

    Convert dynamic PHP include to C#

    I have an application coded in PHP that accepts a user selection and passes that selection by URL back to itself to show something in the page. As an example, I have a list of calculators that a user can select. Each one is displayed as a URL. When the user clicks the URL the page is refreshed and shows the user the calculator they chose based on a value passed by the query string.

    PHP Code:
    if (isset($_GET['calc_id']))
    $path_to_calcs "calc_" $_GET['calc_id'] . ".php");
    //load a fresh page with a list of available selections as a post back
            //use an array to store calc id's and link references
    foreach ($calc_array as $calc_id => $calc_ref)
    '<a href="' $_SERVER['PHP_SELF'] . '?calc_id=' $calc_id '">' $calc_ref '</a>';
    How can this be done in C#? All help is appreciated.

  2. #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Thanked 40 Times in 40 Posts
    Something like this? My form was WebForm1, I didn't make any form to accept a selection, but this should give you an idea...
    // kinda like an associative array
    SortedList calcs = new SortedList();
    private void links()
    	// add values to sortedlist
    	calcs.Add("Calc1", "1");
    	calcs.Add("Calc2", "2");
    	calcs.Add("Calc3", "3");
    	// loop through list and create links
    	foreach(DictionaryEntry calc in calcs) 
    		Response.Write("<a href=" + Request.ApplicationPath + "/WebForm1.aspx?calcId=" + calc.Value + ">" + calc.Key + "</a><br>");
    private void Page_Load(object sender, System.EventArgs e)
    	// our calc id
    	string calcId = Request.QueryString.Get("calcId");
    	if(calcId != null)
    		// Write out the file...
    		Response.WriteFile("Calc" + calcId + ".html");
    		// load links...
    Note: Response.WriteFile() can write out HTML or client side scripts, not server side code. This should help explain... Also, look into User Controls Which is what you'll want to include server side pages. I'll try to post an example over the weekend.
    Last edited by Brandoe85; 07-15-2005 at 06:31 AM. Reason: Added links


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts