Not able to get textbox value from aspx to aspx.cs file if ReadOnly="True" for a textbox

Hi,

I got a problem in .Net 3.5. Lets see my requirement...

a) I have a web page with two text boxes with an image beside the first text box. When I click on the image some opertation will happen in Javascript and a popup with calender should appear and I can select a date from that. After that I will get the selected date to my aspx file with document.getElementID().value. And I will keep it into a string and then I will add 3 more days to it and will print that value in another textbox.

b) When a value is selected or changed in the first textbox then TextChanged event should be fired in aspx.cs file and will print the value which is selected or changed in the textbox 1 and textbox 2. But this not happening.

c) With some trail and error methods I found that If the textbox is ReadOnly="true" then TextChanged event is not firing in aspx.cs file. But if ReadOnly="false" then TextChanged event is firing in aspx.cs file.

So, this would not be good in a customer point of view. A date field should not be readonly as a layman can enter the date manually instead of clicking the image.

Please help me in this.

Thanks in advance..

Anil.

2
AnilKumar_502
12/30/2008 11:46:36 AM
asp.net.web-forms 93655 articles. 5 followers. Follow

11 Replies
3695 Views

Similar Articles

[PageSpeed] 47

TextChanged Event Fires only when you type in the Text and then loose focus from the TextBox. When you are updating the text using Javascript the TextChange Event Will not fire

even if the TextBox had Readonly = false

Solution is when you update the TextBox using javascript do

document.forms[0].submit();

 

then on PageLoad do

If (Request.Params[Textbox1.UniqueID] != null)

String str = Request.Params[Textbox1.UniqueID].ToString().Trim()

End If

This will give the value of TextBox


MAKMark as Answer if this reply helps you
MVP ASP/ASP.Net
MVP ASP/ASP.Net
ASP.Net Hosting : Host DepotMy Site : ASPSnippets
0
mudassarkhan
12/30/2008 12:59:37 PM

 add onchange attribute to textbox in page_load

 

txtBox.Attributes.Add("onchange", "__doPostBack('" + txtBox.ClientID + "', 'Value to pass along');");
 
this will call manual postback to the page
in page_load
add this code
 
if(!IsPostBack)
{
if (Request["__EVENTTARGET"] == txtBox.ClientID)
{
string myArgument = Request["__EVENTARGUMENT"].ToString();
 
//you will get updated txtBox.Text here
}
} 

 


Zeeshan Umar

~ Please Mark as Answer if it solves your query ~
1
sirdneo
12/30/2008 2:33:06 PM

sirdneo:
txtBox.Attributes.Add("onchange", "__doPostBack('" + txtBox.ClientID + "', 'Value to pass along');");

The onchange event fires when you manually change the textbox value and not when the value is modified using javascript So your code will not work.

Test it out here's the code

<asp:TextBox ID="TextBox1" onchange = "alert();" runat="server"></asp:TextBox>

<input id="Button1" onclick = "document.getElementById('TextBox1').value = 'MAK'" type="button" value="button" />

 

Here im changing the value on Button Click the Alert will not fire. But I manully type in or modify text the event will fire


MAKMark as Answer if this reply helps you
MVP ASP/ASP.Net
MVP ASP/ASP.Net
ASP.Net Hosting : Host DepotMy Site : ASPSnippets
0
mudassarkhan
12/30/2008 2:43:53 PM

 Agree with you mudassar .... You really pointed out my mistake. THanks for your time.

 

 

 


Zeeshan Umar

~ Please Mark as Answer if it solves your query ~
0
sirdneo
1/1/2009 5:48:35 AM

 a) I have a web page with two text boxes with an image beside the first text box. When I click on the image some opertation will happen in Javascript and a popup with calender should appear and I can select a date from that. After that I will get the selected date to my aspx file with document.getElementID().value. And I will keep it into a string and then I will add 3 more days to it and will print that value in another textbox.

 

 

 Where you are setting document.getElementID().value call document.getElementID().onchange();


Zeeshan Umar

~ Please Mark as Answer if it solves your query ~
0
sirdneo
1/1/2009 5:50:50 AM

AnilKumar_502:
a) I have a web page with two text boxes with an image beside the first text box. When I click on the image some opertation will happen in Javascript and a popup with calender should appear and I can select a date from that. After that I will get the selected date to my aspx file with document.getElementID().value. And I will keep it into a string and then I will add 3 more days to it and will print that value in another textbox.
 

Check this  http://forums.asp.net/t/1299843.aspx?PageIndex=2

AnilKumar_502:

b) When a value is selected or changed in the first textbox then TextChanged event should be fired in aspx.cs file and will print the value which is selected or changed in the textbox 1 and textbox 2. But this not happening.

c) With some trail and error methods I found that If the textbox is ReadOnly="true" then TextChanged event is not firing in aspx.cs file. But if ReadOnly="false" then TextChanged event is firing in aspx.cs file.

 

AutoPostBack="true"


We All move to our original place.
Don't forget.

Imran Baloch
0
imran_ku07
1/1/2009 6:05:29 AM

 Instead of using the readonly="true" attribute, use the onkeydown="return false" attribute in the textbox properties.


Bind GridView to Dynamically created DataTable | Bind DataTable to DropDownList

My Blog
0
shahed
1/1/2009 6:17:11 AM

When the TextBox Text is modified using Javascript TextChanged Event wont fire even if TextBox AutopostBack is true even if ReadOnly is False It only Fires when user manually types the text and looses focus on it

Try this out

<asp:TextBox  ID="TextBox1" AutoPostBack = "true" runat="server" ReadOnly = "false" OnTextChanged = "TextBox1_TextChanged"></asp:TextBox>

<input id="Button1" onclick = "document.getElementById('TextBox1').value = 'MAK'" type="button" value="Click" />

 

Protected Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

Response.Write(TextBox1.Text)

End Sub


MAKMark as Answer if this reply helps you
MVP ASP/ASP.Net
MVP ASP/ASP.Net
ASP.Net Hosting : Host DepotMy Site : ASPSnippets
0
mudassarkhan
1/1/2009 6:20:36 AM

Hi Anil,

Just remove the readonly attribute from Property window and add the set the readonly attribute to true a runtime.. It will WorkBig SmileYes

Textbox1.Attributes.Add("readonly","true");

 

This will work and you will get the value of the textbox after Postback.

0
Snehal
1/23/2009 9:20:13 AM

Hi Friends,

I am facing a problem...

I have my source code in .net 1.1. It is working fine. Recently we have converted that code to .net 3.5... here starts the problem...

We have a page where it will search for some data. To search the data we will provide start date and end date. In this date range it will fetch all the data from the table and display it in a datagrid. Now I will save that datagrid to Excel sheet... Here I got the problem....In .net1.1 it is creating a excel file and keeping all the data in it. But in .net 3.5.. Iam able to search the information from the given data range..but when I click on save to Excel.. it is giving problem... only if the date is above 12(EX: if I give 12-12-2009 it is working... but if I give 13-12-2009 and click on save to Excel.. no operation  is happening.) it is not working and no data is saving to Excel file.

 

Please help me in this regard... Thanks in advance...

Anil.

0
AnilKumar_502
1/31/2009 7:41:03 PM

Hi Friends,

I am facing a problem...

I have my source code in .net 1.1. It is working fine. Recently we have converted that code to .net 3.5... here starts the problem...

We have a page where it will search for some data. To search the data we will provide start date and end date. In this date range it will fetch all the data from the table and display it in a datagrid. Now I will save that datagrid to Excel sheet... Here I got the problem....In .net1.1 it is creating a excel file and keeping all the data in it. But in .net 3.5.. Iam able to search the information from the given data range..but when I click on save to Excel.. it is giving problem... only if the date is above 12(EX: if I give 12-12-2009 it is working... but if I give 13-12-2009 and click on save to Excel.. no operation  is happening.) it is not working and no data is saving to Excel file.

 

Please help me in this regard... Thanks in advance...

Anil.

0
AnilKumar_502
1/31/2009 7:47:44 PM
Reply:

Similar Artilces:

accessing "aspx.cs" object in "aspx" file ..help
I have a object DataSet ds ; in my "aspx.cs" file and i am trying to access it in my aspx html code as below <% foreach (DataRow dr in ds.Tables[0].Rows)         { %>.... my aspx file doesnt recognize ds in html part. any idea how to fix it ? by the way, i just want to use classic asp code with aspx file but want to use dataset object ds. i am using .net 2.0 ...please help Modify aspx.cs this way:public partial class MyPage : System.Web.UI.Page { private DataSet _ds; private void ReadData() { // read data into DataSet ...

How can i pass atextbox value from "page1.aspx" to "page2.aspx"
Hi have two pages, page1 and page2. page1 has a textbox whose value i want to pass to page2(on page2_load event). Page two dsplays  photos from a database field and i want to select the photo to display where photo_id = the value of textbox in page1. Iam accessing the photos database using ADO.NET sql query in page2 but i want to retrieve the where parameter("photo_id") from a textbox as mentioned in page1. NOTE: Iam using alinkbutton in page1 to navigate to page two. Any help.--------------------------------------------------No Project Too Eazy.---------------------------------------...

<script runat="server">code</script> in aspx file errors when I try to run same code in mypage.aspx.cs file
This code runs file in the aspx file ---- "Profile" and "MasterPageFile" are defined in Web.config <script runat="server">    protected void Page_PreInit(object sender, EventArgs e)    {        if (Request["master"] != null)        {            switch (Request["master"])            {       ...

I've placed <forms loginUrl="home.aspx"></forms> in web.config and now all users that log in go to default.aspx
I've placed <forms loginUrl="home.aspx"></forms> in web.config and now all users that log in go to default.aspx.        <authentication mode="Forms">        <forms loginUrl="home.aspx"></forms>      </authentication>What attribute I should add, to make the user stay on the same page. Btw when I remove  <forms loginUrl="home.aspx"></forms>, users stay on the same page after login.Thanks. try one of these.....

Changing .text value in textbox runat="server", aspx page
So I notice that i cant set text on texboxed or inputs calling from codebehind, so how can solute this? using jscript? jquery .val() ? a webmethod and then executing it on client side? please advice me if this is possible. Thanks in advance!Please dont forget mark as an answer, if this post helped you... Thanks!C# my main PL in .NET Are you using VB or C#? I'm hoping that the problem is you are in one and you are trying to use code appropriate for the other. You can set the text of a textbox using code behind, as you said you wanted to do. If your textbox with runat="server&qu...

How to read the Hidden Values from Test1.aspx using Server.Tranfer("Test2.aspx", true)?
 Hello! I have a little problem. I have two pages: Test1.aspx and Test2.aspx. At Test1, i have some <input type="hidden"> variables.For example,  lets say tha i have  <input type="hidden" id="BaseName" name="BaseName" runat="server" /> When a user presses the "Submit" button, the onClick() event, loads a sub in VB.NET Code file (Test1.aspx.vb). Inside codefile, i'm making  BaseName.value = "xxx", and then, i'm using  Server.Transfer("Test2.aspx", true) to red...

Is using Request(myTextox.ClientID.Replace("_","$")) a bad way to get the value of a dynamic textbox
 I am aware that if I create my controls before the load event and assign an id to them,then the viewstate automatically will update the controls. Unfortunately, I need values from other controls to create my dynamic textboxes, so I have to create them in the loadcompleted event (where they are not automatically updated by the viewstate).I have found that I can still retreive the values using Request(myTextBox.ClientID.Replace("_","$")) and this will return the value. It appears that ASP.NET sets the client id to Something_Something_Something for the control, but then on the postback, c...

different pages :) take textboxes value in onepage.aspx to textboxes value in secondpage.aspx ?
hello friends i have two pages.. deffault.aspx and newpage.aspx.. and i have textbox1 and textbox2 and textbox3 in deffault.aspx.. i also have textbox1 and textbox2 and textbox3 in newpage.aspx.. how can i take textbox1.text and textbox2.text and textbox3.text in deffault.aspx to textbox1.text and textbox2.text and textbox3.text in newpage.aspx with button1 (button1 should be deffault.aspx or newpage.aspx) when i enter values to textbox1.text and textbox2.text and textbox3.text in deffault.aspx ? cheersMark as me if my question or my answer can be helpful for you :) Within the...

Should "update code lines" and "insert code lines" be same page.aspx or be different (update.aspx and insert.aspx)??
hi friends Should "update code lines" and "insert code lines" be same page.aspx or be different (update.aspx and insert.aspx)? if i use same page.aspx for this, code lines be 1000 lines in page.aspx.vb but one page connect to masterpage... if i use different *.aspx for this, code line be 500 lines in per *.aspx.vb  for per *.aspx... but two pages connect to masterpage.. So i have almost 60 pages (*.aspx).. if i select different *.aspx for update and insert, my pages will be 120 pages (*.aspx) which one should i select ? which one runs high performance ? co...

VS.NET 2005 is ignoring in web.config strict="true". I get no error when I try this: Dim x As Integer = "string"
Hello,I have this in my VS.NET 2005 web.config <compilation debug="true" strict="true" explicit="true">When I do this in my vb code:Dim x As Integer = "string"I get no error. When I hit compilation I also get no error. What am I doing wrong?Thanks for helping!Regards,J. Bauer It's a bug of some sort See this response by Scott Guthriehttp://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=3c1c9898-8076-4f69-a5e2-e99573d03c6e Unfortunately we don’t have a GUI based way to configure this. L It is something we will make sure gets added back in, though, with the next...

Accessing the value of a textbox control in one .aspx file in another .aspx file?
I have an .aspx file called 'register' and in that file is a textbox which the user enters something in. I want to be able to access the value from that textbox in another .aspx file called 'registration_error'. How would I got about doing this? I tried declaring a string variable in the Global.asax file but that didn't work. Thanks Store it into a session variable.Bertrand----This posting is provided "AS IS" with no warranties, and confers no rights. How would I go about doing that? Session["MyTextBoxValue"] = txtBox.Text then on the other side if (Sess...

Url is changed from "\filename.aspx" to "%2ffilename.aspx"
Hi there, I have created a form using ASPX. I recently translated the form to French and saved all of the files in a folder called "French". The following coding is from one of the French forms, as part of an Update Function : Dim dbParam_Page As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter dbParam_Page.ParameterName = "@Page" dbParam_Page.Value = "French/FContinue.aspx" dbParam_Page.DbType = System.Data.DbType.String dbCommand.Parameters.Add(dbParam_Page) Notice the portion in bold. When this link is genera...

Trying to transfer a Web Service made in .NET aspx on my "localhost", to online and getting BC30002: Type 'localhost.Convert' is not defined. error
I think I get the general idea of this error.  The webservice works on my computer as Visual Web Developer somehow makes a temporary server out of my computer.  But when I try to FTP my full ASP page I get an error that localhost is not defined.  This makes sense as I am sure the web server for GoDaddy is not called localhost for me.  Now in my App_WebReferences folder in my program I have a local host folder that holds 3 automatically generated files which are somehow "calls" to a webservice that I built.  So I have the original files for the webservi...

How to insert a row of data from "Textbox form" into a "Gridview"
Hi friends, I searched google also, but really couldnt find a solution to my problem. I got a gridview named PersonGridView which lists the datas that are stored in one the table of my database. Selecting, Updating and Deleting properties of my gridview works successfully. But I couldnt add the last property: INSERT For this, I coded nice input form made of Textboxes and Labels like below: .   . <tr> <td><asp:Label ID="Label1" runat="server" Text="Name" Font-Names="Verdana" Font-Size="Small" Height=&q...

Web resources about - Not able to get textbox value from aspx to aspx.cs file if ReadOnly="True" for a textbox - asp.net.web-forms

Resources last updated: 12/24/2015 2:13:31 AM