Mohamed Faisal Abbas Mohamed Faisal Abbas - 3 months ago 19
ASP.NET (C#) Question

How to show the panel in postback?

I have two radio button in group called

purchase and Expenses
.
When i click purchase radio button, that will show
panelpurchase
,similarly
panelexpense
will show for Expenses radio button.

watch image of outputwhen pageload panelpurchase visible false using jquery

when i click purchase radio button that will show panelpurchasepanelpurchase show.

now what i want is when i click the add button in panelpurchase that page will reload (postpack) and that postback page should display that panel purchase.

jquery code:

<script type="text/javascript">

$(document).ready(function () {

$('#PanelPurchase').hide();
$('#PanelExpensive').hide();
$('#<%= RadioPurchase.ClientID %>').click(function () { $('#PanelPurchase').show(); $('#PanelExpensive').hide(); });
$('#<%= RadioExpensive.ClientID %>').click(function () { $('#PanelPurchase').hide(); $('#PanelExpensive').show(); });

$('#btnAdd').click(function () {
alert("faisal");
//$('#PanelPurchase').show(); $('#PanelExpensive').hide();
})
});
</script>


Back end c# code:

protected void btnAdd_Click(object sender, EventArgs e)
{
PanelPurchase.Visible = true;
Response.Write("server working");
}

Answer

In button click you call the javascript function like below;

protected void btnAdd_Click(object sender, EventArgs e)
    {
        PanelPurchase.Visible = true;
        Response.Write("server working");
        Page.ClientScript.RegisterStartupScript(this.GetType(),"CallMyFunction","MyFunction()",true);
    }

Then define the javascript function,

function MyFunction()
{
   $('#PanelPurchase').show();
   $('#PanelExpensive').hide();

}