Solved

client side javascript for VB.net

Posted on 2013-06-04
6
304 Views
Last Modified: 2013-08-23
I have a custom textbox control which I need to be readonly, but i am having trouble posting back the page and retaining the value of the box in a web page.

I read that you could set the read-only via javascript on the client side which allows the values to repost and still gives the appearance of readonly.  I found the sample java code, but I am sure how to call that via the textbox control.  There is a onload option, would that be the best place?

I believe this control is basedon the text box control. HOw would you apply this javascript to the standard textbox control?
0
Comment
Question by:red_75116
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 11

Assisted Solution

by:MajorBigDeal
MajorBigDeal earned 250 total points
ID: 39220482
If you put the data in a hidden field, you can load it back into the control on the page load event.  Example: http://forums.asp.net/t/1428896.aspx/1

You could also actually add your updated info into the viewstate for the control so that .net would persist it for you but I don't recommend that approach.
0
 
LVL 25

Assisted Solution

by:Ron Malmstead
Ron Malmstead earned 125 total points
ID: 39220519
Why can't you just do ..

textbox1.enabled = false

?
0
 
LVL 18

Assisted Solution

by:Rajar Ahmed
Rajar Ahmed earned 125 total points
ID: 39220985
If u set by this,

//txtbox1.ReadOnly=false;

or in

//<asp:textbox readonly="false"

Just remove  those lines

Try by this,
txtbox1.Attributes.Add("readonly","readonly");

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:red_75116
ID: 39253481
I still cannot get this to work.  My application uses a custom textbox called inputfield.  When I add the readonly= true to the below, the field is readonly, but when posting back to the page, the values are lost.

                <ex:InputField runat="server" ID="ifReceiver" Readonly="true" />


I was told if I could make the field be readonly with clientside script, it would appear read only and the postback would still work.

How do I call this javascript?
0
 
LVL 11

Accepted Solution

by:
MajorBigDeal earned 250 total points
ID: 39378282
Modifying the field in a client side script will not cause the change to be automatically posted back.  The way to accomplish this is to put the data you want to post back into a hidden field and then load it back to the control on the page load event.  Here is an example:  http://forums.asp.net/t/1428896.aspx/1

You could try to directly modify the viewstate on the client-side so that it would get posted back but that is difficult and error-prone.  Unfortunately, it is not a simple matter of just loading the data into the field on the client-side.
0
 

Author Closing Comment

by:red_75116
ID: 39433193
I was able to get the results I needed via the viewstate.  Thanks so much for the help
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question