TextBox1 value

Discussion in 'ASP .Net' started by =?Utf-8?B?cm9kY2hhcg==?=, Nov 12, 2007.

  1. hey all,
    i'm trying to use the onblur client-side event to get the value of TextBox1
    but can't seem to nail down the syntax. can someone please help?

    thanks,
    rodchar
    =?Utf-8?B?cm9kY2hhcg==?=, Nov 12, 2007
    #1
    1. Advertising

  2. On Nov 12, 8:54 pm, rodchar <> wrote:
    > hey all,
    > i'm trying to use the onblur client-side event to get the value of TextBox1
    > but can't seem to nail down the syntax. can someone please help?
    >
    > thanks,
    > rodchar


    you can use Attributes.Add

    TextBox1.Attributes.Add("onblur","...");
    Alexey Smirnov, Nov 12, 2007
    #2
    1. Advertising

  3. =?Utf-8?B?cm9kY2hhcg==?=

    bruce barker Guest

    <asp:textbox id="textbox1"
    runat="server"
    onblur="alert(this.value);" />

    -- bruce (sqlwork.com)

    rodchar wrote:
    > hey all,
    > i'm trying to use the onblur client-side event to get the value of TextBox1
    > but can't seem to nail down the syntax. can someone please help?
    >
    > thanks,
    > rodchar
    bruce barker, Nov 12, 2007
    #3
  4. On Nov 12, 9:35 pm, bruce barker <> wrote:
    > <asp:textbox id="textbox1"
    > runat="server"
    > onblur="alert(this.value);" />
    >
    > -- bruce (sqlwork.com)
    >


    hm... bruce, are you sure? onblur is a DOM event, it's not an
    attribute of the TextBox server control
    Alexey Smirnov, Nov 12, 2007
    #4
  5. If asp.net doesn't recognize an attribute, it will just render it as it is:

    <asp:textbox id="textbox1" runat="server" abc="xyz" />

    will render as

    <input type="text" id="textbox1" abc="xyz" />

    --
    Eliyahu Goldin,
    Software Developer
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin
    http://usableasp.net


    "Alexey Smirnov" <> wrote in message
    news:...
    > On Nov 12, 9:35 pm, bruce barker <> wrote:
    >> <asp:textbox id="textbox1"
    >> runat="server"
    >> onblur="alert(this.value);" />
    >>
    >> -- bruce (sqlwork.com)
    >>

    >
    > hm... bruce, are you sure? onblur is a DOM event, it's not an
    > attribute of the TextBox server control
    >
    Eliyahu Goldin, Nov 13, 2007
    #5
  6. On Nov 13, 10:07 am, "Eliyahu Goldin"
    <> wrote:
    > If asp.net doesn't recognize an attribute, it will just render it as it is:
    >
    > <asp:textbox id="textbox1" runat="server" abc="xyz" />
    >
    > will render as
    >
    > <input type="text" id="textbox1" abc="xyz" />
    >
    > --
    > Eliyahu Goldin,
    > Software Developer
    > Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
    >


    Well, this would make a warning regarding wrong attribute and when you
    have treat warnings as errors turned on you will not be able to build
    the project (code-behind). So, is this the best way?

    You can also use <input runat="server" onblur=....
    Alexey Smirnov, Nov 13, 2007
    #6
  7. I am not saying it is the best way, I am saying it will work.

    I personally use the Attributes collection, and I definitely like <input
    runat="server" onblur=....more than <asp:textbox runat="server" onblur=....

    --
    Eliyahu Goldin,
    Software Developer
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin
    http://usableasp.net


    "Alexey Smirnov" <> wrote in message
    news:...
    > On Nov 13, 10:07 am, "Eliyahu Goldin"
    > <> wrote:
    >> If asp.net doesn't recognize an attribute, it will just render it as it
    >> is:
    >>
    >> <asp:textbox id="textbox1" runat="server" abc="xyz" />
    >>
    >> will render as
    >>
    >> <input type="text" id="textbox1" abc="xyz" />
    >>
    >> --
    >> Eliyahu Goldin,
    >> Software Developer
    >> Microsoft MVP
    >> [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
    >>

    >
    > Well, this would make a warning regarding wrong attribute and when you
    > have treat warnings as errors turned on you will not be able to build
    > the project (code-behind). So, is this the best way?
    >
    > You can also use <input runat="server" onblur=....
    >
    Eliyahu Goldin, Nov 13, 2007
    #7
  8. Hi Im trying to add the onfocus event to a textbox contained in datalist. I
    can add the attribute but the code just doesnt work.

    I can add a texbox to a web page and in code behind add following ;

    Me.TextBox1.Attributes.Add("onfocus", "this.value='';")
    Me.TextBox1.Attributes.Add("onblur", "this.value='Click here';")

    This works great, how can you do it with the textbox in a datalist. I can
    the attribute the same by using the ItemCommand event but the javascript does
    not work.

    Thanks

    Neil

    "Eliyahu Goldin" wrote:

    > I am not saying it is the best way, I am saying it will work.
    >
    > I personally use the Attributes collection, and I definitely like <input
    > runat="server" onblur=....more than <asp:textbox runat="server" onblur=....
    >
    > --
    > Eliyahu Goldin,
    > Software Developer
    > Microsoft MVP [ASP.NET]
    > http://msmvps.com/blogs/egoldin
    > http://usableasp.net
    >
    >
    > "Alexey Smirnov" <> wrote in message
    > news:...
    > > On Nov 13, 10:07 am, "Eliyahu Goldin"
    > > <> wrote:
    > >> If asp.net doesn't recognize an attribute, it will just render it as it
    > >> is:
    > >>
    > >> <asp:textbox id="textbox1" runat="server" abc="xyz" />
    > >>
    > >> will render as
    > >>
    > >> <input type="text" id="textbox1" abc="xyz" />
    > >>
    > >> --
    > >> Eliyahu Goldin,
    > >> Software Developer
    > >> Microsoft MVP
    > >> [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
    > >>

    > >
    > > Well, this would make a warning regarding wrong attribute and when you
    > > have treat warnings as errors turned on you will not be able to build
    > > the project (code-behind). So, is this the best way?
    > >
    > > You can also use <input runat="server" onblur=....
    > >

    >
    >
    >
    =?Utf-8?B?TmVpbCBTdGV2ZW50b24=?=, Nov 16, 2007
    #8
  9. I haven't used a DataList, but for most list-based controls there is a
    "ItemCreated" event. Inside that event you can get references to template
    controls using (Sender as DataList).FindByName("ControlName").

    > I can add a texbox to a web page and in code behind add following ;
    >
    > Me.TextBox1.Attributes.Add("onfocus", "this.value='';")
    > Me.TextBox1.Attributes.Add("onblur", "this.value='Click here';")
    >
    > This works great, how can you do it with the textbox in a datalist.
    Scott Roberts, Nov 16, 2007
    #9
  10. Yep I have used the event ItemCreated as such ;

    Dim tmpTextBox As TextBox
    tmpTextBox = CType(e.Item.FindControl("txtQty"), TextBox)
    tmpTextBox.Attributes.Add("onfocus", "this.value='';")

    Ive found out that the code works in firefox the way I want but its IE not
    playing ball, so Im just trying to find out why. ? hate problems like this ,
    a nice error msg would have been helpfull.

    Neil

    "Scott Roberts" wrote:

    > I haven't used a DataList, but for most list-based controls there is a
    > "ItemCreated" event. Inside that event you can get references to template
    > controls using (Sender as DataList).FindByName("ControlName").
    >
    > > I can add a texbox to a web page and in code behind add following ;
    > >
    > > Me.TextBox1.Attributes.Add("onfocus", "this.value='';")
    > > Me.TextBox1.Attributes.Add("onblur", "this.value='Click here';")
    > >
    > > This works great, how can you do it with the textbox in a datalist.

    >
    >
    =?Utf-8?B?TmVpbCBTdGV2ZW50b24=?=, Nov 16, 2007
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. al
    Replies:
    7
    Views:
    4,081
    George
    Jun 17, 2004
  2. Replies:
    2
    Views:
    379
  3. Replies:
    1
    Views:
    1,037
    =?Utf-8?B?TWFuaXNoIEJhZm5h?=
    Feb 4, 2007
  4. Jado
    Replies:
    0
    Views:
    137
  5. Jado
    Replies:
    0
    Views:
    112
Loading...

Share This Page