CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2010
    Posts
    130

    [RESOLVED] Override method in Master page?

    Hey,

    I have created a multiple page website in ASP.NET/C# with a Master Page acting as template. The Master Page contains the navigation buttons and their appropriate links. On clicking a particular navigation button from a particular page, I would like the data on that page to be saved. The most logical way of doing this seems to me to be to create an overrideable method in the Master Page called OnPageSubmission() which is called every time a link is clicked. The page in question would then override this method and save the data on it's page to the database. Is this possible and how do I go about programming this in the Master Page?

    My navigation buttons are set in the ASP.NET side of the Master Page and are called imgbtnAzubi, imgbtnBeur and so forth...

    Code:
    // On clicking img btn Azubi transfer to page Azubi
            protected void ImgbtnAzubi_Click(object sender, ImageClickEventArgs e)
            {
                try
                {
                    // Save the page state
                    //OnPageSubmission();
    
                    // Transfer page
                    Response.Redirect("TraineeSelection.aspx", true);
                }
                catch(HttpException)
                {
                    Azubiportal.ErrorPage.SetError("404");
                    errorPage.DisplayErrorMsg();
                }
            }
    
            // On clicking Beurteilung transfer to that page
            protected void ImgbtnBeurt_Click(object sender, ImageClickEventArgs e)
            {
                try
                {
                    // ONLY if the current page is complete can progress!
                    if (completedPageAzubi == true)
                    {
                        Response.Redirect("ReportSelection.aspx", true);
                    }
                    else
                    {
                        MessageBox("Bitte Wählen Sie einen Azubildender zur Bewertung aus.");
                    }
                }
                catch (HttpException)
                {
                    Azubiportal.ErrorPage.SetError("404");
                    errorPage.DisplayErrorMsg();
                }
            }
    
    (...)
    The page in question could then have a method called OnPageSubmission()
    Code:
    protected override void OnPageSubmission()
    {
           // Calls a method which sets the page's data
           SaveData();
    }

  2. #2
    Join Date
    Dec 2009
    Posts
    1

    Re: Override method in Master page?

    We have different methods to maintain the design standard (style for server controls) in a .NET application.
    For instance,
    We can do it by using Theme – by assigning the name of Theme File In each page or
    We can once set it in Web.config file
    We can also do it by applying css to every page.

    If you are using Master Page in your application , the following method describes one more way of achieving this .
    If Your .NET application Uses Master Page then add the following line of code in the master page .By this you have to just call the function in the Master page.
    <style type="text/css">
    .normalfld
    {
    background-color: #FFFFFF;
    }
    .focusfld
    {
    background-color: #FFFFCC;
    border-color:#33CCFF; color:Maroon ;
    }
    .HiddenColumn{display:none;
    </style>
    <script type="text/javascript">
    function DoBlur(fld)
    {
    fld.className = 'normalfld';
    }
    function DoFocus(fld)
    {
    fld.className = 'focusfld';
    fld.SkinID = "txtblue"
    }
    function DoBlur(fld)
    {
    fld.className = 'normalfld';
    }
    function DoFocus(fld)
    {
    fld.className = 'focusfld';
    fld.SkinID = "txtblue"
    }
    </script>




    protected void Page_Load(object sender, EventArgs e)
    {
    addBlurAtt(ContentPlaceHolder1);

    }
    private void addBlurAtt(Control cntrl)
    {
    if (cntrl.Controls.Count > 0)
    {
    foreach (Control childControl in cntrl.Controls)
    {
    addBlurAtt(childControl);
    }
    }
    if (cntrl.GetType() == typeof(TextBox))
    {
    TextBox TempTextBox = (TextBox)cntrl;
    TempTextBox.Attributes.Add("onfocus", "DoFocus(this);");
    TempTextBox.Attributes.Add("onblur", "DoBlur(this);");
    }

    if (cntrl.GetType() == typeof(DropDownList))
    {
    DropDownList TempTextBox = (DropDownList)cntrl;
    TempTextBox.Attributes.Add("onfocus", "DoFocus(this);");
    TempTextBox.Attributes.Add("onblur", "DoBlur(this);");
    }
    }

    This way you can expand the function for different controls of your application.

    hope you find it useful

    Thanks
    Suryakant

  3. #3
    Join Date
    Jan 2010
    Posts
    130

    Re: Override method in Master page?

    I am not sure I understand what you are saying :S

    What is the aim of these methods that you listed?

    I never knew you could put javascript in CSS!

  4. #4
    Join Date
    Jan 2010
    Posts
    130

    Re: Override method in Master page?

    Thank you for your reply. I found a different way using a BaseWebPage with an overriding method called OnPageSubmission().

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured