Referencing an HTML Element in the code-behind?-VBForums
Results 1 to 10 of 10

Thread: Referencing an HTML Element in the code-behind?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    3,954

    Referencing an HTML Element in the code-behind?

    I'm trying to set a value for an HTML Element within my code-behind. I need to set a <div> elements "display" property to "inline". The way I have it coded is like this:
    Code:
         divContact.Style("display") = "inline"
    Is this the right syntax? I only ask because it doesn't seem to work but I don't get a run-time error when the statement is executes. ???

    Thanks,
    Blake

  2. #2
    Hyperactive Member
    Join Date
    Sep 2006
    Location
    India
    Posts
    308

    Re: Referencing an HTML Element in the code-behind?

    Try this:
    divContact.Attributes.Add("style","display:inline");
    Sagar
    VB6, VB.net,C#,ASP, ASP.net MSSQL, MYSQL

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    3,954

    Re: Referencing an HTML Element in the code-behind?

    Sorry...I should have explained a little better along with the scenario.

    What is happening is that I have a <div> that contains a Submit Button along with some textboxes (It's basically a data entry screen). By default, when the page loads, this <div> is not visible (display: none). When I click on a menu option, this <div> will appear. When I click on the Submit button, the Click Event for this button doesn't fire right away, rather, the Page_Load() event executes first, causing the <div> to become hidden again, which I don't want. Then the Click event fires executing a function that performs edit checks against the textboxes.

    The bottom line is that if I want the <div> to remain visible even if an alert statement displays a message during the edits. I hope I've explained this well enough.

    Thanks,
    Blake

  4. #4
    Hyperactive Member
    Join Date
    Sep 2006
    Location
    India
    Posts
    308

    Re: Referencing an HTML Element in the code-behind?

    why cant you add your 'display:none' in not post back??

    if (!IsPostBack)
    {
    //div hide here
    }

    So it will not hide again.
    Sagar
    VB6, VB.net,C#,ASP, ASP.net MSSQL, MYSQL

  5. #5
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,962

    Re: Referencing an HTML Element in the code-behind?

    Hello,

    Have you thought about calling the necessary methods from the client side, using say jQuery, rather than using a button to do a full page post back to the server?

    Gary

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    3,954

    Re: Referencing an HTML Element in the code-behind?

    Brother...I'm still trying to learn Javascript. JQuery is next on the list though...
    Blake

  7. #7
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,962

    Re: Referencing an HTML Element in the code-behind?

    jQuery is fast becoming the "defacto" way of interacting with the server, so much so that the jQuery nuget package is now included in the New Project Template within Visual Studio. I would strongly encourage you to start looking at it.

    Gary

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    3,954

    Re: Referencing an HTML Element in the code-behind?

    Can you refer me to any online sites that are great with tutorials and such?

    Thanks
    Blake

  9. #9
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,962

    Re: Referencing an HTML Element in the code-behind?

    Hey,

    More and more, I have been directing people to the online video training site Pluralsight:

    http://pluralsight.com/training

    They are not free, but there is a free trial that you can use, but they have a fantastic collection of videos, and in my opinion, well worth the money if you decide you like them.

    In addition to those, you will also find a done of information here:

    http://docs.jquery.com/

    And as I mentioned, take a look at the project templates that already exist in Visual Studio (especially 2012 Update 2) where there are numerous Single Page Application templates, that make extensive use of jQuery.

    Hope that helps!

    Gary

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    3,954

    Re: Referencing an HTML Element in the code-behind?

    Thanks Gary, I appreciate your help!

    God Bless
    Blake

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.