Assign to a HTML textbox a value with asp.net

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?ZWdzZGFy?=

    #1

    Assign to a HTML textbox a value with asp.net

    I had to create a HTML textbox to add the date time but I don't know how to
    assign the value with asp.net, how can I do that?

    This is my HTM Textbox code:

    <input id="txtFechaPla n" name="txtFechaP lan" style="width: 124px; position:
    static" type="text" />

    Thx

  • Mark Rae [MVP]

    #2
    Re: Assign to a HTML textbox a value with asp.net

    "egsdar" <egsdar@discuss ions.microsoft. comwrote in message
    news:FBE7FE05-1455-4C67-A01F-34BB61E21878@mi crosoft.com...
    I had to create a HTML textbox to add the date time but I don't know how
    to
    assign the value with asp.net, how can I do that?
    >
    This is my HTM Textbox code:
    >
    <input id="txtFechaPla n" name="txtFechaP lan" style="width: 124px;
    position:
    static" type="text" />
    Change the client-side markup to:
    <input type="text" id="txtFechaPla n" runat="server"
    style="width:12 4px;position:st atic;" />

    Add the following to the code-behind, probably in the Page_Load event:
    txtFechaPlan.Te xt = DateTime.Now.To String("dd MMM yyyy HH:mm");


    --
    Mark Rae
    ASP.NET MVP


    Comment

    • Patrice

      #3
      Re: Assign to a HTML textbox a value with asp.net

      Try :


      <input type="text" runat="server"w ill use server side a programming model
      that closely match the one used client side.

      You can also use an <asp:TextBox runat="server"c ontrol that will use
      server side a programming model that is similar to Windows Forms (but
      ultimately it will of course still be rendered as an input type="text"
      markup...

      --
      Patrice

      "egsdar" <egsdar@discuss ions.microsoft. coma écrit dans le message de
      groupe de discussion : FBE7FE05-1455-4C67-A01F-34BB61E21878@mi crosoft.com...
      I had to create a HTML textbox to add the date time but I don't know how
      to
      assign the value with asp.net, how can I do that?
      >
      This is my HTM Textbox code:
      >
      <input id="txtFechaPla n" name="txtFechaP lan" style="width: 124px;
      position:
      static" type="text" />
      >
      Thx
      >

      Comment

      • Hillbilly

        #4
        Re: Assign to a HTML textbox a value with asp.net

        In other words, we can add runat="server" to --any-- HTML element and it can
        then be parsed and compiled as an HTML Control. If you need to reference an
        HTML Control it must be typed as HtmlGenericCont rol, i.e.

        HtmlGenericCont rol textInput = FindControl("tx tFechaPlan") as
        HtmlGenericCont rol;

        //search
        html control site:msdn.micro soft.com




        "egsdar" <egsdar@discuss ions.microsoft. comwrote in message
        news:FBE7FE05-1455-4C67-A01F-34BB61E21878@mi crosoft.com...
        >I had to create a HTML textbox to add the date time but I don't know how to
        assign the value with asp.net, how can I do that?
        >
        This is my HTM Textbox code:
        >
        <input id="txtFechaPla n" name="txtFechaP lan" style="width: 124px;
        position:
        static" type="text" />
        >
        Thx
        >

        Comment

        • =?Utf-8?B?ZWdzZGFy?=

          #5
          Re: Assign to a HTML textbox a value with asp.net

          Thanks for the post, but I did as you suggest and it works, however, this
          textbox is associated with a script and when I add the runat tag the
          javascript doesn't work, this is the full aspx code:



          <input id="txtFechaPla n" name="txtFechaP lan" style="width: 124px; position:
          static" type="text" runat="server" />

          <a href="javascrip t:NewCal('txtFe chaPlan','yyyym mdd',true,24,'a rrow')">

          <img src="Images/date.png" style="position : static" border="0" /></a>



          How can I make them both work?


          "Mark Rae [MVP]" wrote:
          "egsdar" <egsdar@discuss ions.microsoft. comwrote in message
          news:FBE7FE05-1455-4C67-A01F-34BB61E21878@mi crosoft.com...
          >
          I had to create a HTML textbox to add the date time but I don't know how
          to
          assign the value with asp.net, how can I do that?

          This is my HTM Textbox code:

          <input id="txtFechaPla n" name="txtFechaP lan" style="width: 124px;
          position:
          static" type="text" />
          >
          Change the client-side markup to:
          <input type="text" id="txtFechaPla n" runat="server"
          style="width:12 4px;position:st atic;" />
          >
          Add the following to the code-behind, probably in the Page_Load event:
          txtFechaPlan.Te xt = DateTime.Now.To String("dd MMM yyyy HH:mm");
          >
          >
          --
          Mark Rae
          ASP.NET MVP

          >
          >

          Comment

          • Mark Rae [MVP]

            #6
            Re: Assign to a HTML textbox a value with asp.net

            "egsdar" <egsdar@discuss ions.microsoft. comwrote in message
            news:73B8B305-5A67-4373-B182-9985992F6D04@mi crosoft.com...
            >Change the client-side markup to:
            ><input type="text" id="txtFechaPla n" runat="server"
            >style="width:1 24px;position:s tatic;" />
            >>
            >Add the following to the code-behind, probably in the Page_Load event:
            >txtFechaPlan.T ext = DateTime.Now.To String("dd MMM yyyy HH:mm");
            >
            Thanks for the post, but I did as you suggest and it works, however, this
            textbox is associated with a script and when I add the runat tag the
            javascript doesn't work, this is the full aspx code:
            >
            <input id="txtFechaPla n" name="txtFechaP lan" style="width: 124px;
            position:
            static" type="text" runat="server" />
            >
            <a href="javascrip t:NewCal('txtFe chaPlan','yyyym mdd',true,24,'a rrow')">
            >
            <img src="Images/date.png" style="position : static" border="0" /></a>
            As a general rule, when posting to a technical newsgroup, there is very
            little point in saying simply that something "doesn't work" if you don't
            actually say why it doesn't work, what error messages you are getting etc.
            That will help us to help you. All I can do now is guess why it doesn't
            work...

            Firstly, remove the name="txtFechaP lan" tag, as I originally advised e.g.
            <input type="text" id="txtFechaPla n" runat="server"
            style="width:12 4px;position:st atic" />

            Then try this:
            <a
            href="javascrip t:NewCal('<%=tx tFechaPlan.Clie ntID%>','yyyymm dd',true,24,'ar row')">

            As mentioned, I can't guarantee this will solve your problem because you
            haven't explained what your problem is...


            --
            Mark Rae
            ASP.NET MVP


            Comment

            Working...