Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How can Access a Div without add runar="server" in code behind?

How can Access a Div without add runar="server" in code behind?

Scheduled Pinned Locked Moved ASP.NET
sysadminhelpquestion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    anoop_m83
    wrote on last edited by
    #1

    protected void Page_Load(object sender, EventArgs e)
    {
    HtmlGenericControl div = (HtmlGenericControl)Page.FindControl("mydiv");
    if (div != null)
    {
    div.InnerHtml = "test message";
    }
    }

    i used this code, but not working? is there any solution? i search google but cant get relevant answer. please help me.

    N D 2 Replies Last reply
    0
    • A anoop_m83

      protected void Page_Load(object sender, EventArgs e)
      {
      HtmlGenericControl div = (HtmlGenericControl)Page.FindControl("mydiv");
      if (div != null)
      {
      div.InnerHtml = "test message";
      }
      }

      i used this code, but not working? is there any solution? i search google but cant get relevant answer. please help me.

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      The obvious question is why not add the runat attribute?


      I know the language. I've read a book. - _Madmatt

      A 1 Reply Last reply
      0
      • N Not Active

        The obvious question is why not add the runat attribute?


        I know the language. I've read a book. - _Madmatt

        A Offline
        A Offline
        anoop_m83
        wrote on last edited by
        #3

        if i did add runat="server" i can access mydiv.innerText from .cs page. please let me know if any way to access that.

        N 1 Reply Last reply
        0
        • A anoop_m83

          if i did add runat="server" i can access mydiv.innerText from .cs page. please let me know if any way to access that.

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          When you add a runat=server attribute to an html element it is automatically wrapped as a HtmlGenericControl. Your first attempt gained you nothing. So rather than this

          HtmlGenericControl div = (HtmlGenericControl)Page.FindControl("mydiv");
          if (div != null)
          {
          div.InnerHtml = "test message";
          }

          You could have this

          div.InnerText = "test message";


          I know the language. I've read a book. - _Madmatt

          A 1 Reply Last reply
          0
          • N Not Active

            When you add a runat=server attribute to an html element it is automatically wrapped as a HtmlGenericControl. Your first attempt gained you nothing. So rather than this

            HtmlGenericControl div = (HtmlGenericControl)Page.FindControl("mydiv");
            if (div != null)
            {
            div.InnerHtml = "test message";
            }

            You could have this

            div.InnerText = "test message";


            I know the language. I've read a book. - _Madmatt

            A Offline
            A Offline
            anoop_m83
            wrote on last edited by
            #5

            when i add runat="server" no need to access via

            HtmlGenericControl div = (HtmlGenericControl)this.FindControl("mydiv");

            please check this image[^] thank you for your time.

            1 Reply Last reply
            0
            • A anoop_m83

              protected void Page_Load(object sender, EventArgs e)
              {
              HtmlGenericControl div = (HtmlGenericControl)Page.FindControl("mydiv");
              if (div != null)
              {
              div.InnerHtml = "test message";
              }
              }

              i used this code, but not working? is there any solution? i search google but cant get relevant answer. please help me.

              D Offline
              D Offline
              doudoufly
              wrote on last edited by
              #6

              You can not access a Div without add runar="server" in code behind. But you can get input element without add runar="server" like this: in code behind string pName = Request.Form['pName'];

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups