TextBox1 value

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
 
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

you can use Attributes.Add

TextBox1.Attributes.Add("onblur","...");
 
B

bruce barker

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

-- bruce (sqlwork.com)
 
G

Guest

<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
 
G

Guest

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=....
 
E

Eliyahu Goldin

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


Anon User 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=....
 
G

Guest

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


Anon User 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=....
 
S

Scott Roberts

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").
 
G

Guest

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top