Solved

client side javascript for VB.net

Posted on 2013-06-04
6
299 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
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 M
Ron M 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to access a DataBinder.Eval variable using C# ? 4 27
Help with solving error related to resources file 4 35
DataGridView Events ? 3 37
vb.net checkbox 7 41
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

932 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now