Results 1 to 14 of 14

Thread: include a variable in html

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    include a variable in html

    HI,

    I need to do this simple code in html. I need to include a variable(fullname) from Comments.html inl another form like

    'Fullname' thankyou for giving us your comments.

    thankyou
    ------------------------------------------------------------------------
    If an answer to your question has been helpful, then please, Rate it!

  2. #2
    Lively Member
    Join Date
    Jan 2010
    Location
    Republic of Macedonia
    Posts
    114

    Re: include a variable in html

    You should have a patter that is not easy to be mixed with the remaining content. For instance you can say:
    %%Fullname%% thankyou for giving us your comments.

    Then before you display the page get the content and replace the %%Fullname%% with an appropriate value.

    Code:
    TheContent = TheContent.Replace("%%Fullname%%", FullNameTextBox.Text)

  3. #3
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: include a variable in html

    Hey,

    The code above would be used within the Server Side code of an ASP.Net Application, but you specifically mention using html.

    Can you perhaps give some more information about what exactly you are trying to achieve so that we can make sure you get it working.

    Gary

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Re: include a variable in html

    I am trying to import the user name (fullname) which is inputted in a textbox from another page within the same webpage and get it to show up. Like

    Angelica, thankyou for you comments

    where Angelica would have been inputted in the texbox for the username.
    ------------------------------------------------------------------------
    If an answer to your question has been helpful, then please, Rate it!

  5. #5
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: include a variable in html

    this is not an HTML but to get the textbox value of the previous page from the code behind you should do something like:

    Code:
     string FullName = ((TextBox)Page.PreviousPage.FindControl("txbFullName")).Text;
    you can also get the textbox value with the form collection

    Code:
    string fullName = Request.Form["txbFullName"];
    if you using master page and using the "Request.Form" method you should take into consideration that the textbox control ID will change and then you should use the ClientID property.
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

  6. #6
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: include a variable in html

    Hey,

    Are these user's people who have logged into your website, or can these be any people? If they are logged into your website already, then you can get this information from the built in methods within the Framework.

    Or, in addition to the methods that motil has mentioned, you could put the username into a Session variable, or append it to the QueryString.

    There are a number of different ways to do this, it just depends on exactly what you are doing, and why you are doing it.

    Gary

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: include a variable in html

    Page2:

    Label1.Text = String.Format("{0}, thank you for your comments", firstName);


    On Page1, you can accept the user's comments in the button click event, save or email it (or whatever you want to do), then either

    Response.Redirect("~/page2.aspx?name=" + TextBox1.Text);

    or

    Session["firstName"] = TextBox1.Text;
    Response.Redirect("~/page2.aspx");

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Re: include a variable in html

    Hi ALL,

    thanks for your replies. Is there a way to do the same thing using only HTML? I am teaching this class of student where I can only use html and they have no ASP.Net knowledge.

    thanks
    ------------------------------------------------------------------------
    If an answer to your question has been helpful, then please, Rate it!

  9. #9
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: include a variable in html

    as far as i know, nope.... maybe with javascript/.
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

  10. #10
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: include a variable in html

    Hey,

    If your question was specifically related to using only HTML, why did you post in the ASP.Net forum?

    One way you could do this would be to use JavaScript to get the value in the querystring, and change the label value.

    Here is one implementation:

    http://www.bloggingdeveloper.com/pos...avaScript.aspx

    Gary

  11. #11
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: include a variable in html

    On the first page, you can set the form's method to get

    <form action="page2.html" method="get">
    <input type="text" id="fname" name="fname" />
    <input type="submit" value="go" />
    </form>

    When you click submit, it'll go to

    page2.html?fname=blah&something=something

    So you could then use that javascript to read the querystring and write it to the page. If page2 has a textbox for example, you could use

    document.getElementById('page2textbox').value = valueFromQueryString;

  12. #12
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: include a variable in html

    Would you like this moved to the HTML forum?

  13. #13

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Re: include a variable in html

    Thanks


    Yes I think it more belongs to the HTML . Thankyou.
    ------------------------------------------------------------------------
    If an answer to your question has been helpful, then please, Rate it!

  14. #14
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: include a variable in html

    Moved.

    Did you try what we've suggested so far?

Posting Permissions

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



Click Here to Expand Forum to Full Width