2 Ways i can suggest:
1) Remove all jQuery code and show/hide your
Div
at server side only, however your
div
is having
runat="server"
attribute
protected void btnEdit_Click(object sender, EventArgs e)
{
divEdit.visible= true;
divAddress.visible= false;
txtName.Text = "abcdef";
}
protected void btnCancel_Click(object sender, EventArgs e)
{
divEdit.visible= false
divAddress.visible= true;
}
2) Still if you want to use Jquery
(However doing so will look foolish :), not the best way at all ), the code you have wrote will work until your server side click event triggers.. and the
show/hide
state of
DIVs
will be lost after postback.. so you have to set the status somewhere and get it back after the postback... You can use
Hiddenfield
to set the current status and then set div status accordingly
See below code..
<input type="hidden" id="hdStatus" value="0" />
$(document).ready(function(){
Var hdStatus= $("#hdStatus").value();
if(hdStatus==0)
{
$('#<%=divAddress.ClientID %>').show();
$('#<%=divEdit.ClientID %>').hide();
}
else
{
$('#<%=divAddress.ClientID %>').hide();
$('#<%=divEdit.ClientID %>').show();
}
$('#<%=btnEdit.ClientID %>').click(function(){
$("#hdStatus").value("1");
$('#<%=divAddress.ClientID %>').hide();
$('#<%=divEdit.ClientID %>').show();
});
$('#<%=btnCancel.ClientID %>').click(function(){
$("#hdStatus").value("0");
$('#<%=divAddress.ClientID %>').show();
$('#<%=divEdit.ClientID %>').hide();
});
});
Hope this will help
[Please "Accept Answer" if it helps you]