asp.net/c# dynamic html control name attribute problem

Discussion in 'C#' started by ranacseruet, Aug 20, 2009.

  1. #1
    I am having problem in setting a name attribute on a dynamic html control, my setted name isn't getting, what its getting is something like "ctl120" etc... how to get rid of this?

    
                TextBox tempInput = new TextBox();
                tempInput.Text = row["TimeIn"].ToString();            
                tempInput.Attributes.Add("id", "txtTimeIn" + i.ToString());
                tempInput.Attributes.Add("name",i.ToString());          
                tempInput.Attributes.Add("value", tempInput.Attributes["name"]);
                tempData.Controls.Add(tempInput);
                tempRow.Cells.Add(tempData);
    
    Code (markup):
    Outputs:

    
    <input name="ctl20" value="1" type="text">
    
    Code (markup):

     
    ranacseruet, Aug 20, 2009 IP
  2. ccoonen

    ccoonen Well-Known Member

    Messages:
    1,606
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    160
    #2
    .NET needs a hook to your control - so it needs to set the name if it is going to be created by .NET - Name is off limits... even if you gave it a name via tags as in <a href="blah" runat="server" name="hehe" /> it will alter the html created control name.
     
    ccoonen, Aug 20, 2009 IP
  3. juno.tiwari@gmail.com

    juno.tiwari@gmail.com Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I will give this work my name is juno tiwari
    and my Email id
     
    juno.tiwari@gmail.com, Aug 27, 2009 IP