How to create web form class object and use it.

Posted on 2011-10-20
Medium Priority
Last Modified: 2012-05-12
I have situation.
in my asp.net application I have web page which has a master page.
User can create an PDF file at the run time by using this form. on the form i have few grid, labels controls which I am using to get data for PDF file.

Now my clients said he want to create the same pdf file from a different web form.
I am trying to avoid copying same code.

I need to know can create an object of my web form class in my second web form and call the Create pdf method to create the pdf file.

but I also want to load all controls so that pdf have the correct values.
Question by:ziorinfo

Accepted Solution

gery128 earned 500 total points
ID: 37004801
Why do you want to create object and populate all those controls in other page?

You can utilize the same webform for creating the pdf in new page. What you can do is, on second page, on clicking some link like create pdf or on page load, display first form in modal dialog or if the second form has nothing (its blank) than on page load of second form just make Server.Transfer("/FirstForm.aspx"); URL would be the same in browser.

Author Comment

ID: 37004841
the issue with me here is create pdf method needs to be called after executing few line of code which does some database update.

and first form which has create pdf form has controls and I need to load these controls so that while creating pdf I can pick values from them

Expert Comment

ID: 37004858
So, you have some controls on second form ( non-pdf form) ? And want to use it in pdf-creating-form?
If you want to execute DB updates, you can do it in page-life-cycle event early in second form and then load the first form (pdf-creating-form) in a modal which will show up to user with all contents. You don't need worry about first form's (pdf-creating-form) controls to be populated and other things, that would be done automatically. just chose the a good modal dialog from several JS based techniques.
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

LVL 26

Expert Comment

by:Anurag Thakur
ID: 37005015
What I have understood is that your PDF generation logic and the look and feel of the page generating the PDF (data capturing etc) is the same on both the pages

If this is correct, my suggestion will be convert the existing code into a user control and the reuse the functionality in the new page

Expert Comment

ID: 37005264
ragi0017 has suggested another way of achieving the required.
If you still have confusion, elaborate your problem more.

Expert Comment

ID: 37005289
So I am not sure what you are looking for, advise as to whether to create a class or how to create a class.

To me if I understand what you have done so far it seems a general class that you can call from any page would seem to be a good idea.

To create a class you go to add new item and select class. See part example of a class I use called ddItems and I have named the namespace ListClasses;

In the page I wish to create the instance of the class I add

using ListClasses;

then I can create my instance like this:

doc.Ditem = new List<ddItems>();

Does any of this help? Obviously the class you define will be very different than these but it shows you the type of thing you need to do to get started.

using System.Data.SqlClient;
using System.Configuration;

namespace ListClasses

    public class ddItems
        private int _rowno;
        private int _dateno;
        private int _ddindex;
        private string _absence;

        public ddItems()
            Rowno = 0;
            Dateno = 0;
            Ddindex = 0;
            Absence = "Not available";

        public int Rowno        {
            get { return _rowno; }
            set { _rowno = value; }
        public int Dateno
            get { return _dateno; }
            set { _dateno = value; }
        public int Ddindex
            get { return _ddindex; }
            set { _ddindex = value; }
        public string Absence
            get { return _absence; }
            set { _absence = value; }


    public class Doctor
        private int _persno;
        private string _name;
        private IList<ddItems> _ditem;
        private Boolean _enabel;

        public Doctor()
            Persno = 0;
            Name = "Not available";
            Ditem = null;


        public int Persno
            get { return _persno; }
            set { _persno = value; }
        public string Name
            get { return _name; }
            set { _name = value; }

        public IList<ddItems> Ditem
            get { return _ditem; }
            set { _ditem = value; }

        public Boolean Enabel
                return _enabel;
                _enabel = value;

        public void LoadDoctors()
        string insertSQL = "UPDATE person SET LastnameT = 'Test' WHERE LastnameT = 'Browne'";
        SqlConnection testConn = new SqlConnection();
        testConn.ConnectionString = ConfigurationManager.ConnectionStrings["DocConnection"].ConnectionString;

        SqlCommand cmd = new SqlCommand(insertSQL, testConn);

        int updated;
            updated = cmd.ExecuteNonQuery();
        catch (Exception err)

Open in new window


Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question