sharepoint: How to programmatically open a custom form

I have a custom list instance. I used SharePoint Designer to create custom form which allows users to add new items. I wish to create a webpart with a button (-> opens my custom form). Basically: How to use c# to dipslay a form? I am using SharePoint 2010.
LVL 1
tolppaAsked:
Who is Participating?
 
ivan_vaguninCommented:
Hi! First you should know url of your custom form (I guess you can see it in SPD).
Then the link to open form in popup will be following: javascript:SP.UI.ModalDialog.ShowPopupDialog('{FormUrl}?ID={ItemId});
0
 
tolppaAuthor Commented:
Thanks, ivan.  I know my local url, but I would like to create solution that allows can be deployed to different machines / site collections etc. Perhaps I should use c# to generate this url, but then again, why not to use c# to open the form at the first place? Is that something I need to use javascript to do?
0
 
ivan_vaguninCommented:
Let me explaing, if you want form to open in popup window the only way is to use execute javascript. There are two ways to execute javascript - on user action (e.g. button click) or register a startup script from server code. I guess registering startup javascript is more difficult, then just add onclick javascript hanlder for the button.

But, if you want to open list form in the same window (not popup) you can use Response.Redirect() in server code - to redirect user to custom form.
0
 
tolppaAuthor Commented:
Thanks. I believe you solved my problem. How to find ItemId (ID={ItemId})? Expecially guids keep giving me a head ache.
0
 
ivan_vaguninCommented:
ItemId is not guid (unique id), but integer ID - you can add ID column in listview and see IDs for items.
For example http://myserver/Lists/MyList/MyForms.aspx?ID=1
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.