ascx Templates c# code not added

  • Thread starter Thread starter Joe
  • Start date Start date
J

Joe

I've set up my template according to all directions.

VSNet's own template for the WebUser Control uses:

1. Under "Program Files\Microsoft Visual Studio .NET
2003\VC#\VC#Wizards\CSharpAddWebUserControl", there are a template file
(WebUserControl.ascx), a list of templates (template.inf) and a script file
that drives the customization (default.js).

2. The code behind template NewWebUserControlCode.cs is put at "Program
Files\Microsoft Visual Studio .NET 2003\VC#\DesignerTemplates\1033"

I cannot get any thing other then the code behind template:
"NewWebUserControlCode.cs" to get entered, when I invoke my wizard.

How do I get my wizard ( a new custom web user control ), to use a different
code behind and not use:
Program Files\Microsoft Visual Studio .NET
2003\VC#\DesignerTemplates\1033\NewWebUserControlCode.cs" ?

OR

If one must edit: NewWebUserControlCode.cs for their own, how does one keep
the "default" Microsoft ? How does one make two web user control templates
that require DIFFERENT code behinds?

Thanks for your time....
 
Hello Joe,

Thanks for your post.
different code behind and not use:
Program Files\Microsoft Visual Studio .NET
2003\VC#\DesignerTemplates\1033\NewWebUserControlCode.cs" ?

I suggest that you should create a new template of your own (say,
MyCustomTemplates), and refer to the CSharpAddMobileWebFormWiz under
C:\Program Files\Microsoft Visual Studio .NET 2003\VC#\VC#Wizards\ which
includes the MobileWebForm1.aspx.cs under the templates directory. And all
we need is to do the following steps:

1. Add the MobileWebForm1.aspx.cs to our MyCustomTemplates\templates\1033
directory, rename it to WebForm1.aspx.cs.

2. Rename the default.js in the MyCustomTemplates\scripts\1033 directory to
old default.js

3. Copy default.js script from CSharpAddMobileWebFormWiz\scripts\1033 to
MyCustomTemplates\scripts\1033 and open it in VS.NET or notepad.

4. Go to line 278 and change "MobileWebForm1.aspx.cs" to "WebForm1.aspx.cs"

5. Go to line 278 and change "MobileWebForm1.aspx" to "WebForm1.aspx" you
will now need the old default.js,

6. Open it in a text editor and go to line 2 copy all 3 first functions
shown here :
function AddDefaultServerScriptToWizard(selProj)
{
wizard.AddSymbol("DEFAULT_SERVER_SCRIPT", "JavaScript");
}

function AddDefaultClientScriptToWizard(selProj)
{
var prjScriptLang = selProj.Properties("DefaultClientScript").Value;
// 0 = JScript
// 1 = VBScript
if(prjScriptLang == 0)
{
wizard.AddSymbol("DEFAULT_CLIENT_SCRIPT", "JavaScript");
}
else
{
wizard.AddSymbol("DEFAULT_CLIENT_SCRIPT", "VBScript");
}
}

function AddDefaultDefaultHTMLPageLayoutToWizard(selProj)
{
var prjPageLayout = selProj.Properties("DefaultHTMLPageLayout").Value;
// 0 = FlowLayout
// 1 = GridLayout
if(prjPageLayout == 0)
{
wizard.AddSymbol("DEFAULT_HTML_LAYOUT", "FlowLayout");
}
else
{
wizard.AddSymbol("DEFAULT_HTML_LAYOUT", "GridLayout");
}
}

7. Copy them to your new default.js

8. go to line 59 (function AddFileToVSProject) and add calls to these
functions:
AddDefaultServerScriptToWizard(selProj);
AddDefaultTargetSchemaToWizard(selProj);
AddDefaultClientScriptToWizard(selProj);
AddDefaultDefaultHTMLPageLayoutToWizard(selProj);
Notice that there is an extra call here to
AddDefaultTargetSchemaToWizard(selProj) this function adds the target
schema to tha page and is not existed in the original default.js file (dont
know where it comes from...) but it works so I don't really care right now.

9. open the WebForm1.aspx.cs and remove the references System.Web.Mobile
and System.Web.UI.MobileControls

10. change the inheritance of the web page to from this :
public class myPage1 : System.Web.UI.MobileControls.MobilePage
to this : public class myPage1 : System.Web.UI.Page

11. add some of your code to the code behind.
private void initializePageParams()
{
//....
}

private void BindGrid()
{
//
}

//whatever you want...

That's about it, save all your work and close all instances of VS.NET open
a web project and add an item using your template .

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top