Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a master page. Then i have several content pages, Lets say I have 2 content pages for now cp1 and cp2.
Each content page has a form that will have some user input and a SaveData() function that saves the data to a database.

I want to kep a common save button in the master page. when cp1 is opned if i click the save button then cp1 input data is saved.
when cp2 is opned if i click the save button then cp2 input data is saved.

What sould i do?
Posted
Updated 28-Dec-10 19:50pm
v3

Do something like this on content pages

Do not specify any button click handler in the master page, instead specify one for each content page. You may try:
In page_load for each content page:
Button btn = this.Master.FindControl("Button1") as Button; //specify your button id   

btn.Click += new System.EventHandler(myBtnClickHandler);
 
Share this answer
 
Comments
Hiren solanki 28-Dec-10 6:48am    
Good solution, Brij.
Md. Mahfujul 29-Dec-10 1:20am    
When i use a button in master page then the error message shown "A page can have only one server-side Form tag." if remove the form tag the other error shown "Control 'ctl00_btnSave' of type 'Button' must be placed inside a form tag with runat=server". How can i solve this problem???
Brij 29-Dec-10 2:51am    
Add the form tag in master page and remove it from content pages. A rendered page can have only one form tag. So you need to put onlu in master or content page.As per your requirement , you need to put it into master page.
Md. Mahfujul 29-Dec-10 3:38am    
Thanks for ur solution.. but still i get an error msg "No overload for 'SaveData1' matches delegate 'System.EventHandler'"
Hi,

Your main area of concern is to how you access control of content page into master page.

Here i put a button in master page and a control on content page on button click i have got the control on its value but it is little bit hard coding.

public partial class MasterPage : System.Web.UI.MasterPage
{
    private Control myC;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (this.Page.Title == "first")
        {
            GetControls(this, "TextBox1");
            TextBox myTextBox1 = (TextBox)Convert.ChangeType(myC, typeof(TextBox));
            Response.Write(myTextBox1.Text);
        }        
    }

    public void GetControls(Control c, string FindControl)
    {
        foreach (Control cc in c.Controls)
        {
            if (cc.ID == FindControl)
            {
                myC = cc;
                break;
            }
            if (cc.Controls.Count > 0)
                GetControls(cc, FindControl);
        }

    }    
} 



Refer link is :
[^]
 
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