通过通用的保存按钮保存日期 [英] save a date from a common save button

查看:68
本文介绍了通过通用的保存按钮保存日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个母版页.然后我有几个内容页面,可以说我现在有2个内容页面cp1和cp2.
每个内容页面都有一个表单,该表单将具有一些用户输入,还有一个SaveData()函数,该函数将数据保存到数据库中.

我想在主页上保留一个通用的保存按钮.当CP1被opned如果我点击保存按钮,然后输入CP1数据被保存.
当CP2是opned如果我点击保存按钮,然后输入CP2的数据保存.

我该怎么办?

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?

推荐答案

在内容页面上执行类似的操作

不要在母版页中指定任何按钮单击处理程序,而应为每个内容页指定一个.您可以尝试:
在每个内容页面的page_load中:
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);




您主要关心的领域是如何将内容页面的控制权访问母版页.

在这里,我在母版页上放置了一个按钮,在内容页上单击了一个控件,然后单击按钮,我已经掌握了它的值,但是有点困难.

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


这篇关于通过通用的保存按钮保存日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆