locked
How can I call a variable from another page? RRS feed

  • Question

  • User743508062 posted

    Hi

    I am very stuck on this small part of my project and has become a major block on being able to move on and finish this part of my build.

    This is my code, I am only presenting a small portion of it:

    ...
    
    <div id="dialog-form3" title="Edit Discounts">
    <form id="edit-discount-form">
    
                 <div class="row">
                    <span class="label"><label for="ecustomerid">Customer ID:</label></span>
                    <input type="text" name="ecustomerid" id="ecustomerid" value="~/EditDiscount/@ecustomerid" size="5" />
                </div>
    
                <div class="row">
                    <span class="label"><label for="ecustomercode">Customer Code:</label></span>
                    <input type="text" name="ecustomercode" id="ecustomercode" value="~/EditDiscount/@ecustomercode" size="5" />
                </div>
    
    ...

    Please note the bolded part; ie:

    value="~/EditDiscount/@ecustomerid"

    As you can see I am trying to obtain a value for this column from another page (EditDiscounts). When I run the code I get the error:

    Server Error in '/' Application.
    --------------------------------------------------------------------------------
    Compilation Error 
    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 
    
    Compiler Error Message: CS0103: The name 'ecustomerid' does not exist in the current context
    
    Source Error:
    Line 296:             <div class="row">
    Line 297:                <span class="label"><label for="ecustomerid">Customer ID:</label></span>
    Line 298: <input type="text" name="ecustomerid" id="ecustomerid" value="~/EditDiscount/@ecustomerid" size="5" /> Line 299:            </div>
    Line 300: 
    
    Source File: c:\Users\vijlebbo\Documents\My Web Sites\LensCatalogueSystem\DiscountCustomers.cshtml    Line: 298 
    

    Monday, May 13, 2013 5:50 AM

All replies

  • User379720387 posted

    There are a few options to pass data from page to page, but they pretty much boil down to you taking an action at the originating page, and then retrieving the data on the receiving page.

    For instance at the originating page you pass data in the URL along these lines :

     Response.Redirect("~/Members/Entry/" + clientid + "/" + carid);    
    

    At the receiving page:

    int clientid = UrlData[0].AsInt

    int carid = UrlData[1].AsInt

    Look for "passing data between pages" at mikesdotnetting to find other options.

    Monday, May 13, 2013 7:48 AM
  • User743508062 posted

    Hi wavemaster, thanks for the reply. I really appreciate all the help you give.

    I need advice at this stage. Can you tell me what would be my best method to amend/update data.

    I have followed your sample of the add/edit data in the Evonet tutorials. It is these codes that I am attempting to modify and use for my project.

    Initially I had the relevant Jquery, modal form code and (and the variables) all housed in my main discount page called CustomerDiscount.

    I had the IsPost in another page called EditDiscount.

    When I ran the code I managed to amend the data but because I did not use the Where clause, all discount rows were amended. So I am using the Where clause in my update statement. But now I get an XMLhttpRequest being shown.

    At the same time all my Customers that have not had their discounts put on ie have Null discounts all come back with a Null binding error.

    So my request is what should I be doing? what would you suggest in my case? many thanks.

    Monday, May 13, 2013 8:00 AM
  • User379720387 posted

    Take smaller bites and simplify your problem. Make sure that individual functionality works first before you try to put it all together.

    I would create a single page that has the entire update cycle and make that work first.

    Check out my answer in your other thread.

    Monday, May 13, 2013 8:10 AM
  • User-2121587974 posted

    Try building the string first.  I have some issues when I try to push the @variable up against other text inside of quotes.

    @{
        int ecustomerid = 1234;
        string str= "~/EditDiscount/" + ecustomerid.toString();
    }
    <input type="text" name="ecustomerid" id="ecustomerid" value="@str" size="5" />


    Thursday, May 30, 2013 4:50 AM