Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Client side changes of div title are not being reflected in C# code behind

I have a problem with my div element title. The following is my div element:

<div id="sampleDiv" runat="server" class="exStyle" onclick="return div_Click(this);" title="any"></div>

The following is my javascript:

function div_Click(btn) {
    if (btn.title == "any") {
        btn.title = "on";
        btn.style.background = "url('sample1.png')";
    }
    else if (btn.title == "on") {
        btn.title = "off";
        btn.style.background = "url('sample2.png')";
    }
    else if (btn.title == "off") {
        btn.title = "any";
        btn.style.background = "url('sample3.png')";
    }
    return false;
}

and after changing the title to "on" or "off" from client side, the value of Attributes["title"] from c# code behind is still "any"!! Any help guys...

like image 972
Vanest Avatar asked Dec 28 '25 01:12

Vanest


1 Answers

What are you trying to do? Since title is attribute it is never posted back to server. Only input element are posted back to server. There fore you are unable to get the changed value.

To bypassthis restriction you will have to add hiddenfield with runat server tag. update hiddenfield value to the div title before post and recover the value in your code behind by using hiddenfield. value.

Hope this is clear.

like image 113
Ratna Avatar answered Dec 30 '25 13:12

Ratna