Monday 11 April 2011

Why does object.style.background='url()' cause postback?


Look at the following code:

Here is what you figure it out:









Problem is that each time focus is set for TextBox, a postback occurs. You can realize
it if you place a debug point in Page_Load()
protected void Page_Load(object sender, EventArgs e)
    {
    }



It runs into same problem even in every browser. I have no idea of what the reason might be, nor how to solve it. But I came across a workaround when I play with CSS. Here is what I'm gonna show it:

Firstly, place TextBox background reset block into CSS and change style from JavaScript through CssClass:


    



Secondly, replace onfocus="this.style.background = 'url()';" by onfocus="txtOnFocus(this);"


Now, it works just fine.


No comments:

Post a Comment