Click here to Skip to main content
15,891,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I have two ASP pages.
In the page1 I have two buttons (btn1 and btn2), in page2 also I have two buttons (insert and update),If I click the btn1 in page1 database data are show in page2 assigned TextBox while I need to disable the insert button in page2.
If I click btn2 in page1, TextBox are shown in empty while I need to disable the update button in page2.
How can I disable these two buttons in different event.

Thanks
Posted
Updated 29-Feb-12 3:12am
v2
Comments
Oshtri Deka 29-Feb-12 8:02am    
This is school project, isn't it?

In your first page you can store result of your program logic to ViewState...

C#
protected void btn1_click(object sender, EventArgs e)
{
    this.ViewState["behavior"] = "update";
}

protected void btn1_click(object sender, EventArgs e)
{
    this.ViewState["behavior"] = "insert";
}

...and later you send that result as parameter via QueryString to you second page.
C#
if(ViewState["behavior"] != null)
{
    Response.Redirect("page2Url goes here?Behavior=" + ViewState["behavior"].ToString());
}
else
{
    //Business as usual
}


With information sent as parameter you can easily in Load event of second page set desired behavior/property values on targeted controls.
C#
protected void Page2_Load(object sender, EventArgs e)
{
    if(!this.IsPostBack)
    {
        string arg = null;
        arg = Request.QueryString["behavior"];

        if(arg != null)
        {
            btnUpdate.Enabled = arg == "update";
            btnInsert.Enabled = arg == "insert";
            myTextBox.Text = btnInsert.Enabled ? "" : "bind some data on your own!";
        }
    }
}
 
Share this answer
 
In your first page while clicking the buttons you are redirecting to another page so instead of viewstate and checking the text box content pass a value with url as query string based on the value you can show or hide buttons in second page.
 
Share this answer
 
You can disable on Page/Form load event of page2

C#
if(textbox.Text =="")
{
updbtn.ReadOnly=true;
insetbtn.ReadOnly=false;
}
else
{
pdbtn.ReadOnly=false;
insetbtn.ReadOnly=true;

}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900