Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

How to add a form to a web part in Visual Studio 2005

  Asked By: Madhu    Date: Mar 18    Category: Sharepoint    Views: 2420

I'm trying to create a form which integrates into my Sharepoint site
that updates an external SQL database. I'm having trouble understanding
exactly what I need to do to add a form to a newly create web part in
VS 2005. When I create a form in a regular web application I just right-
click and add a new item but this is not available in this web part
template. How do I insert a form into my web part?



21 Answers Found

Answer #1    Answered By: Anthony Rutledge     Answered On: Mar 18

Webparts are essentially specialized versions of server controls. That means
they have a code file, but no design surface like a web  page. However, the code
added is essentially the same. Each web part  is the rough equivalent of an ASPX
page in a standard web environment. The code that you add  to the web part is
99% the same as what you would add to the web page. Add a Form to your ASP.net
website and then look at the code in the designer generated code. That's
basically the code that you will write in your web part.

That's a bit of an oversimplification, but essentially true.

Answer #2    Answered By: Heena Nagori     Answered On: Mar 18

Is there any reason you wouldn't just use a BDC? Is this SharePoint 2007 or

Answer #3    Answered By: Aishwarya Karmarkar     Answered On: Mar 18

There are several ways to approach this.

In a web  part, you can write the code to create and display the form, create
the data connrction, etc. As Paul said, this is done without the benefit of
visual aids. There are books written on how to do this.

Alternately, you can create the form  in a standard ASP.NET web page, save it
as a user control (.ascx), and add  that to your web part. This will give you
the visual  tools while you build the form, but isn't as efficient as a pure
code solution.

You can also take the ASP.NET route and use a web part  page library to
display the form in a SharePoint page. This is a loosely bound solution so
is quite easy to break, but is probably the simplest method. In your site,
create a web part page, select the full template, and add a page viewer web
part. Modify that web part to link to your web page, and set the size of the
web part to display the entire page. Generally, you would design the web
page to display only the form (i.e. no banner, navigation, footer, etc.) as
the SharePoint page will provide everything else.

Tutorials for all of these approaches can be found on the web.

Answer #4    Answered By: Janell Camacho     Answered On: Mar 18

You can also use SharePoint Designer to add  Data View web  parts. I'm not
sure how to update or insert records in a SQL DB using this method though.
Anybody have experience with this?

Answer #5    Answered By: Julia Washington     Answered On: Mar 18

I tried using this method but I could not figure out how to add
dropdown lists and other controls to the form  fields.

Answer #6    Answered By: Shashwat Takle     Answered On: Mar 18

I would need some clarity on your goals here. What other type of
controls are you attempting to add  to the page? Is your focus on the
Data View/Data Form web  part?

Answer #7    Answered By: Aastha Acharya     Answered On: Mar 18

I been tasked with moving our current paper employee forms to online
fill-in forms. We do not have Forms server or the Enterprise edition
and do not want to purchase Infopath for all of our employees. So
we've decided to go the ASP.net route.

We would like to have a separate page for each form  and also be able
to use workflow with this. (Is it even possible to use the workflow
with creating my own custom forms?)

I tried using the data form web  part in SharePoint Designer but could
not figure out how to add  dropdown lists to the fields. At the time
there were no books out on SD..not sure if this is still the case.

Answer #8    Answered By: Glenda Roth     Answered On: Mar 18

I assume these forms are going to be submitted to a SharePoint list/library;
if that is the case, then why not just use a modified Add Item form  in

Answer #9    Answered By: Jada Clemons     Answered On: Mar 18

We were planning to have the data added to an external SQL db.

Answer #10    Answered By: Brooke Lewis     Answered On: Mar 18

Would I still be able to pull the user login credentials from
Sharepoint into my form  using this method?

Answer #11    Answered By: Talia Johns     Answered On: Mar 18

With web  Parts, you would have full security context and Object Model
access. With Web part  Pages, where you are just linking to another web page,
it would be in a different application. I'm still doing research on this, so
can;t give you a better answer at the moment.

Answer #12    Answered By: Tera Callahan     Answered On: Mar 18

In SharePoint the current user can be obtained from the
SPContext.Current.Web.CurrentUser object. This object contains properties that
you can use to get the Login.

Answer #13    Answered By: Mark Davis     Answered On: Mar 18

Do you know of a good book or class that will teach me VS including
how to build SP web  parts? I only have experience with classic ASP
and am very new to VS and developing in SP.

Answer #14    Answered By: Delilah Mcpherson     Answered On: Mar 18

Yes, I started out in that class but moved to SP Designer because I
had just started working with SP and thought the developer class was
too in-depth for me at that point in time. My boss probably won't
approve that kind of expense for this year since I already went to
the designer class and I'm going to the Devconnections conference in
Vegas in November.

Answer #15    Answered By: Gobinda Navalagi     Answered On: Mar 18

Refere book "Developer's Guide to
the Windows SharePoint Services v3 Platform".

Answer #16    Answered By: Rose Silva     Answered On: Mar 18

The BDC is read only, you cannot use it to write input to a
database. Other options that haven't been mentioned are InfoPath
2007 with Forms Server (only if you are running MOSS 2007 Enterprise)
and Jan Tielen's SmartPart control which allows you to host user
controls (developed with the drag and drop design surface) in a ready
made, easy to use web  part. I used this technique extensively when I
was starting out in web part  development because it allowed me to get
a thorough understanding of web part concepts (how when and where
they are best used, connections, performance and usability issues)
whilst producing working, usable solution

Answer #17    Answered By: Maegan Ellison     Answered On: Mar 18

PS the other benefit of using Jan's excellent SmartPart control is
that it is open source (http://www.codeplex.com/smartpart). When you
are ready to move onto the next step and write your own web  parts
form scratch then where better to start than Jan's code - it covers
everything you'll need to know from the basics (exposing properties
and using interfaces to enable connections) through to the more
advanced techniques like caching and making your web parts AJAX

Answer #18    Answered By: Yahaira Shannon     Answered On: Mar 18

BDC is NOT inherently Read Only. It is however normally used that way since you
are usually accessing a database in a Line Of Business Application without going
through the business rules that are stored in the application. Take a look at
the following web  article.


Answer #19    Answered By: Doris Leach     Answered On: Mar 18

I stand corrected, Paul's link is very useful in pointing out the
GenericInvoker method of the BDC object model (which I haven't come
across before, thanks!) There is no UI so you would still have to
produce the forms yourself and the method looks *very* generic so IMO
the requirements would have to demand use of the BDC to justify the
extra work e.g. mixing data from your line of business systems with
SharePoint list and library data.

Answer #20    Answered By: Sumitra 2004     Answered On: Mar 18

I'm not familiar with BDC at all. Can you direct me to a good
article explaining BDC?

Answer #21    Answered By: Bhairavi Damle     Answered On: Mar 18
Didn't find what you were looking for? Find more on How to add a form to a web part in Visual Studio 2005 Or get search suggestion and latest updates.