Reputation: 2215
protected void Page_Load(object sender, EventArgs e)
{
Button cmdTemp = null;
try
{
cmdTemp = (Button)GetPostBackControl(this);
}
catch { }
FillTableDB();
if(IsPostBack)
{
if(cmdTemp == null || cmdTemp.ID == "btnNew" || cmdTemp.ID != "btnSave")
{
GenerateBlankTableHtml("");
}
}
}
private void FillTableDB()
{
//SQL QUERY
//Select status from table
GenerateBlankTableHtml(status)
}
private void GenerateBlankTableHtml(string status)
{
if(status=="")
{
btnNew.Style.Add("Display", "none");
}
else
{
//show status in label
lblStatus.text=status;
}
}
public static Control GetPostBackControl(Page page)
{
Control control = null;
string ctrlname = page.Request.Params.Get("__EVENTTARGET");
if(ctrlname != null && ctrlname != string.Empty)
{
control = page.FindControl(ctrlname);
}
else
{
foreach(string ctl in page.Request.Form)
{
Control c = page.FindControl(ctl);
if(c is System.Web.UI.WebControls.Button)
{
control = c;
break;
}
}
}
return control;
}
ASPX:
<asp:Button ID="btnSave" runat="server"/>
<asp:Button ID="btnNew" runat="server"/>
<asp:Label ID="lblStatus" runat="server"
I have two functions FillTableDB();GenerateBlankTableHtml(string status); When status getting blank i have to hide btnNew otherwise showing status in label. if label having status then and only then New study botton will displayed otherwise not.
What i want when user click on button NEW then and only then i have to show label text with blank status Not click on save button What should i do.
Upvotes: 1
Views: 159
Reputation: 2509
Try this
if(IsPostBack)
{
if(btnNew.Style.Value == "Display:none;")
{
GenerateBlankTableHtml("");
}
}
protected void btnNew_Click(object sender, EventArgs e)
{
GenerateBlankTableHtml("");
}
Upvotes: 1
Reputation: 14216
do something like following.
<asp:Button ID="btnNew" runat="server" onClick="btnNew_click"/>
and now on that button new click.
protected void btnNew_Click(object sender, EventArgs e)
{
Button btnNew = (Button)sender;
btnNew.Style.Add("Display", "none");
lblStatus.text = string.empty;
}
Upvotes: 1