Results 1 to 8 of 8

Thread: [RESOLVED] How to reference a <div> element using code-behind?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Resolved [RESOLVED] How to reference a <div> element using code-behind?

    I have a <div> element in a web page. I've assigned it an "ID" and made it a server-side control by using "runat=server". How do I define that <div> in the code-behind. I'm been looking at the "System.Web.UI.HtmlControls" namespace and not sure what to use. The reason I need to do this is because within this <div> is a "Submit" button which will cause a postback. When I click the submit button the first thing it does is it executes a procedure to perform edit checks on the various textbox controls. If a control is empty, a message pops up. When the user clicks "Ok" for the message, the <div> disappears because when the form loads, the <div> style.display property is set to "none" by default.

    Maybe there is a better way to control this. Basically, all I want is for the <div> not to disappear when the edit checks are performed and a messagebox pops up. Any ideas?

    Thanks,
    Blake

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: How to reference a <div> element using code-behind?

    Thread moved.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: How to reference a <div> element using code-behind?

    To where?
    Blake

  4. #4
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: How to reference a <div> element using code-behind?

    I believe using a HtmlGenericControl should allow you to access the div.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: How to reference a <div> element using code-behind?

    Thanks kfcSmitty...I'll give it a shot!
    Blake

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

    Re: How to reference a <div> element using code-behind?

    Hello Blake,

    You would only need to do this if you were creating the control on the server side, and then injecting it into the page.

    The fact that you have added the runat=server means that you can reference the already created instance of that div element on the server side.

    Gary

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: How to reference a <div> element using code-behind?

    That Gary...I made some changes and got it working!
    Blake

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

    Re: [RESOLVED] How to reference a <div> element using code-behind?

    Hey,

    Out of interest, what were the changes?

    Gary

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