TextBox1 value

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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","...");
 
<asp:textbox id="textbox1"
runat="server"
onblur="alert(this.value);" />

-- bruce (sqlwork.com)
 
<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
 
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" />

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=....
 
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 said:
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=....
 
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 said:
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 said:
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=....
 
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").
 
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
 
Back
Top