Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have a textbox, when users click in it,i want to display a text.

 

Now, textbox doesnt have "onClick" event. onInit works but that would put the text when the page is loaded. I want the text to appear when users click on the textbox..

 

any ideas?

Posted

I would do it client-side with javascript using the client-side onclick event for the "textbox" (it's actually rendered as an HTML input of type text).

 

There are a few ways you could accomplish this so that when your page is first loaded the text that appears is provided (ahead of time) by your code behind.

 

You can use the Attributes collection of your textbox object in codebehind to create the javascript event code:

 

txtYourTextBox.Attributes.Add("onclick", "this.value='your text here'")

 

Something like this lets you predetermine what text will show but it won't show until the click occurs client-side and no postback is required to make the text show. For example, in the snippet above instead of 'your text here' you might want to provide text based on a variable, database, etc.

 

Or you might use a hidden input to store the text you're going to show and hardcode the javascript to fill the textbox using the hidden input's value.

 

Paul

Posted

Thanks, now i have another issue:

 

I did this:

'Dim test = System.DateTime.Now
       'txtAddNotes.Attributes.Add("onclick", "this.value= '" & test & " " & Session("name") &  " '")

 

I click on the text box, datetime and username appears. so far so good

 

BUT the cursor is on the beginning of the textbox not at the end of the added text!! I click Enter but the text also moves.

 

How can I have the cursor at the end of the added text??

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...