<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Web Forms</title><link>http://forums.asp.net/18.aspx</link><description>All about building ASP.NET Pages - server controls, events, validation, etc.</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Re: ASP.NET 1.1 to 2.0 migration - TextChanged event not firing!</title><link>http://forums.asp.net/thread/1797929.aspx</link><pubDate>Wed, 11 Jul 2007 12:22:00 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1797929</guid><dc:creator>mjofarrell</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1797929.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=18&amp;PostID=1797929</wfw:commentRss><description>&lt;p&gt;Cracked it - one thing I didn&amp;#39;t put in the post above for code brevity (and the fact I didn&amp;#39;t think it mattered)&amp;nbsp;is that the textbox is set readonly (I only want the javascript to enter text into the textbox, not the user):&lt;/p&gt;
&lt;p&gt;&lt;font color="#3366ff"&gt;txtTextBox.ReadOnly = True&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;There is a change between ASP.NET 1.1 and 2.0 that even though a changed textbox value will be sent back in the post variables, the server will ignore it if the textbox is readonly (i.e. it won&amp;#39;t load the new value into the &amp;#39;Text&amp;#39; property of the textbox), hence the TextChanged event won&amp;#39;t fire. This is a security issue addressed by Microsoft to prevent a user circumventing the readonly status of a textbox. They have a workaround where necessary&amp;nbsp;by setting the textbox readonly using the&amp;nbsp;attributes instead:&lt;/p&gt;
&lt;p&gt;&lt;font color="#3366ff"&gt;txtTextBox.Attributes.Add(&amp;quot;readonly&amp;quot;, &amp;quot;readonly&amp;quot;)&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;Techincally this means the server doesn&amp;#39;t know the textbox is readonly and hence follows the correct (IMHO)&amp;nbsp;method of processing the form values (if something must really be readonly for security puposes, and you know this on the server, there are much better ways to ensure data doesn&amp;#39;t get meddled with!). Some more info and related info can be found in these posts:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://scottonwriting.net/sowblog/posts/4965.aspx"&gt;http://scottonwriting.net/sowblog/posts/4965.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://west-wind.com/weblog/posts/3939.aspx"&gt;http://west-wind.com/weblog/posts/3939.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=102065"&gt;http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=102065&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Mark&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>ASP.NET 1.1 to 2.0 migration - TextChanged event not firing!</title><link>http://forums.asp.net/thread/1797777.aspx</link><pubDate>Wed, 11 Jul 2007 10:44:50 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1797777</guid><dc:creator>mjofarrell</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1797777.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=18&amp;PostID=1797777</wfw:commentRss><description>&lt;p&gt;&lt;font size="2"&gt;I am having a problem whilst migrating a web application from ASP.NET 1.1 to ASP.NET 2.0. One of my user controls has a textbox that is not firing its text changed event.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;&lt;/font&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;The textbox&amp;nbsp;is created at run time in a CreateChildControls override on the user control (ph is a placeholder in the .ascx file):&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;&lt;/font&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;font color="#3366ff" size="2"&gt;Protected Overrides Sub CreateChildControls()&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font color="#3366ff" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim txtTextBox As New System.Web.UI.WebControls.TextBox()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; txtTextBox.ID = &amp;quot;foo&amp;quot;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ph.Controls.Add(txtTextBox)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; AddHandler txtTextBox.TextChanged, AddressOf Me.txtTextBox_TextChanged&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font color="#3366ff" size="2"&gt;End Sub&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;&lt;/font&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;To ensure the control gets built early enough to register the event, in Page_Init I have:&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;...&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font color="#3366ff" size="2"&gt;Me.EnsureChildControls()&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;...&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;&lt;/font&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;And I have the handler for the TextChanged event here:&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;&lt;/font&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;font color="#3366ff" size="2"&gt;Private Sub txtTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font color="#3366ff" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;...Event code...&amp;gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font color="#3366ff" size="2"&gt;End Sub&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;&lt;/font&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;Finally, some javascript is&amp;nbsp;squirted out onto the page. This sets the text in the textbox based on a user action (to somethig different to what was there), and then forces the postback by hooking into __doPostback (ctrl is set in javascript to the txtTextBox element): &lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;...&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font color="#3366ff" size="2"&gt;ctrl.value = &amp;#39;some new value&amp;#39;;&lt;br /&gt;&amp;nbsp; __doPostBack(&amp;#39;&amp;#39;,&amp;#39;&amp;#39;);&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;...&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;&lt;/font&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;&lt;strong&gt;So - what is happening:&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;&lt;/font&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;The javascript operates correctly, and I see the text value of the textbox change momentarily to the correct value, the page posts back (and I have even verified that the form values coming back to the parent page are indeed the correct text value). However, I have set a breakpoint, and know that the TextChanged event does not fire on the textbox. The event is designed to set&amp;nbsp;the text into a&amp;nbsp;Session variable. At a later stage in my code, this value in the Session variable is loaded back into the textbox - so without the event firing, the textbox just reverts to what was previously in the session and gets set back to what it was before. &lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;&lt;/font&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;&lt;strong&gt;Some other info:&amp;nbsp;&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;&lt;font size="2"&gt;&lt;strong&gt;&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;Obviously since the page is posting back, __doPostBack is present. If the __doPostBack function is not on the page from other controls, I call GetPostBackEventReference to ensure it gets sent down.&lt;/li&gt;
&lt;li&gt;&lt;/font&gt;&lt;font size="2"&gt;I have tried adding the TextChanged handler before and after (as in this example) adding the textbox to the placeholder - neither works.&lt;/font&gt;&lt;/li&gt;
&lt;li&gt;&lt;font size="2"&gt;In the above example I do not set the __EVENTTARGET parameter of __doPostBack since I have read that the TextChanged event is triggered regardless of what does the post back (i.e. the new form value in the textbox is compared with ViewState to decide whether to raise the event). In my frustration though, I have tried setting the __EVENTTARGET parameter to (what I think is) the correct value (Me.UniqueId.Replace(&amp;quot;:&amp;quot;, &amp;quot;$&amp;quot;) &amp;amp; &amp;quot;$foo&amp;quot;) and the event still doesn&amp;#39;t fire.&lt;/font&gt;&lt;/li&gt;
&lt;li&gt;&lt;font size="2"&gt;I have made no code changes or viewstate changes when migrating - and this all works perfectly in ASP.NET 1.1!!!&lt;/font&gt;&lt;/li&gt;
&lt;li&gt;&lt;font size="2"&gt;Given how close this is to working - maybe it has got something to do with a different page lifecycle in ASP.NET 2.0?&lt;/font&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;font size="2"&gt;Please help - this is driving me nuts!&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;&lt;/font&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;Mark&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&amp;nbsp;&lt;/p&gt;</description></item></channel></rss>