 |
| C# 2008 aka C# 3.0 Discuss the Visual C# 2008 (aka C# 3.0) language |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the C# 2008 aka C# 3.0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

February 20th, 2009, 04:01 PM
|
|
Authorized User
|
|
Join Date: Jan 2009
Posts: 23
Thanks: 10
Thanked 0 Times in 0 Posts
|
|
c# to VB
Hi there
Can anyone tell me how to change the following to Visual Basic? It is for use in an ASP.ET application. Thanks
(PS, I hope I have posted this in the right place)
Code:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
{
TextBox UserNameTextBox =
(TextBox)CreateUserWizardStep2.ContentTemplateContainer.FindControl("UserName");
SqlDataSource DataSource =
(SqlDataSource)CreateUserWizardStep2.ContentTemplateContainer.FindControl("InsertExtraInfo");
MembershipUser User = Membership.GetUser(UserNameTextBox.Text);
object UserGUID = User.ProviderUserKey;
DataSource.InsertParameters.Add("UserId", UserGUID.ToString());
DataSource.Insert();
}
}
|
|

February 20th, 2009, 04:12 PM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
Imports System Imports System.Data Imports System.Configuration Imports System.Web Imports System.Web.Security Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.Web.UI.WebControls.WebParts Imports System.Web.UI.HtmlControls Public Partial Class _Default Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) End Sub Protected Sub CreateUserWizard1_CreatedUser(ByVal sender As Object, ByVal e As EventArgs) Dim UserNameTextBox As TextBox = DirectCast(CreateUserWizardStep2.ContentTemplateContainer.FindControl("UserName"), TextBox) Dim DataSource As SqlDataSource = DirectCast(CreateUserWizardStep2.ContentTemplateContainer.FindControl("InsertExtraInfo"), SqlDataSource) Dim User As MembershipUser = Membership.GetUser(UserNameTextBox.Text) Dim UserGUID As Object = User.ProviderUserKey DataSource.InsertParameters.Add("UserId", UserGUID.ToString()) DataSource.Insert() End Sub End Class
via: http://www.developerfusion.com/tools.../csharp-to-vb/
hth.
-Doug
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click  on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================
|
|

February 20th, 2009, 05:30 PM
|
|
Authorized User
|
|
Join Date: Jan 2009
Posts: 23
Thanks: 10
Thanked 0 Times in 0 Posts
|
|
Thanks Doug
I tried this, but it tells me CreateNewWizard2 is not declared.
I have tried Dim CreateNewWizard2 AS - but this is where I get stuck because it doesn't want to be declared as 'string' or 'integer' and I don't know what else to try!
Any suggestions?
|
|

February 20th, 2009, 05:43 PM
|
 |
Wrox Author
|
|
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
|
|
Quote:
Originally Posted by Spider
Thanks Doug
I tried this, but it tells me CreateNewWizard2 is not declared.
|
That's very strange, as the code contains no reference whatsoever to CreateNewWizard2.
|
|

February 20th, 2009, 05:43 PM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
Is the CreateUserWizardStep you are trying to reference actually called (the ID value) CreateUserWizardStep2??
Additional reference: http://aspnet.4guysfromrolla.com/articles/070506-1.aspx
hth.
-Doug
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click  on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================
|
|

February 21st, 2009, 11:44 AM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
Lee makes a good point. I naturally assumed that it was a typo and that you were actually referring to CreateUserWizardStep2. If it was a typo, no worries, but if it isnt can you please show us the relevant code?
-Doug
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click  on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================
|
|

February 21st, 2009, 05:15 PM
|
|
Authorized User
|
|
Join Date: Jan 2009
Posts: 23
Thanks: 10
Thanked 0 Times in 0 Posts
|
|
Yes! I realised it was a typo on my part
Code:
CreateUserWizardStep2
is what is not declared.
I have tried to declare it using
Code:
Dim CreateUserWizardStep2 as string
and
Code:
Dim CreateUserWizardStep2 as integer
by this stage I am totally coding in the dark as I have no idea what else to try.
|
|

February 21st, 2009, 08:24 PM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
Read over the reference i sent you from 4GuysFromRolla. CreateUserWizardStep2 should actually be declared in your Create User wizard as one of the steps. Trying to declare it in code is going to do you no good.
hth.
-Doug
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click  on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================
|
|

February 22nd, 2009, 09:32 AM
|
|
Authorized User
|
|
Join Date: Jan 2009
Posts: 23
Thanks: 10
Thanked 0 Times in 0 Posts
|
|
I am at a loss with this. The reference from 4guysfromrolla is the very tutorial I was trying to use in the first place (additional billing info is not what I really need but if I could get it to enter this into .mdf then I think that would be half the battle!)
My application uses . vb instead of .cs, hence the issue of translating it in the first place.
The following is the code I have plugged into mine.
Code:
<%@PageTitle=""Language="vb"AutoEventWireup="false"MasterPageFile="~/Navigation.Master"CodeBehind="CreateProfile.aspx.vb"Inherits="ApplicationName.CreateProfile" %>
<asp:ContentID="Content1"ContentPlaceHolderID="head"runat="server">
</asp:Content>
<asp:ContentID="Content2"ContentPlaceHolderID="ContentPlaceHolder1"runat="server">
<asp:CreateUserWizardID="CreateUserWizard1"runat="server"BackColor="#FFFBD6"BorderColor="#FFDFAD"BorderStyle="Solid"BorderWidth="1px"Font-Names="Verdana"Font-Size="0.8em"OnCreatedUser="CreateUserWizard1_CreatedUser">
<WizardSteps>
<asp:WizardStepID="CreateUserWizardStep0"runat="server">
<table>
<tr>
<th>Billing Information</th>
</tr>
<!-- I have cut part of the code from here just to avoid posting a whole screed
</asp:WizardStep>
<asp:CreateUserWizardStepID="CreateUserWizardStep2"runat="server">
<ContentTemplate>
<table>
<tr>
<th>User Information</th>
</tr>
<tr>
<td>Username:</td>
<td>
<asp:TextBoxrunat="server"ID="UserName"/>
<asp:RequiredFieldValidatorrunat="server"ID="RequiredFieldValidator9"ControlToValidate="UserName"ErrorMessage="Username is required."/>
</td>
</tr>
<tr>
<td>Password:</td>
<td>
<asp:TextBoxrunat="server"ID="Password"TextMode="Password"/>
<asp:RequiredFieldValidatorrunat="server"ID="RequiredFieldValidator10"ControlToValidate="Password"ErrorMessage="Password is required."/>
</td>
</tr>
<tr>
<td>Confirm Password:</td>
<td>
<asp:TextBoxrunat="server"ID="ConfirmPassword"TextMode="Password"/>
<asp:RequiredFieldValidatorrunat="server"ID="RequiredFieldValidator13"ControlToValidate="ConfirmPassword"ErrorMessage="Confirm Password is required."/>
</td>
</tr>
<tr>
<td>Email:</td>
<td>
<asp:TextBoxrunat="server"ID="Email"/>
<asp:RequiredFieldValidatorrunat="server"ID="RequiredFieldValidator11"ControlToValidate="Email"ErrorMessage="Email is required."/>
</td>
</tr>
<tr>
<td>Question:</td>
<td>
<asp:TextBoxrunat="server"ID="Question"/>
<asp:RequiredFieldValidatorrunat="server"ID="RequiredFieldValidator12"ControlToValidate="Question"ErrorMessage="Question is required."/>
</td>
</tr>
<tr>
<td>Answer:</td>
<td>
<asp:TextBoxrunat="server"ID="Answer"/>
<asp:RequiredFieldValidatorrunat="server"ID="RequiredFieldValidator14"ControlToValidate="Answer"ErrorMessage="Answer is required."/>
</td>
</tr>
<tr>
<tdcolspan="2">
<asp:CompareValidatorID="PasswordCompare"runat="server"ControlToCompare="Password"
ControlToValidate="ConfirmPassword"Display="Dynamic"ErrorMessage="The Password and Confirmation Password must match."></asp:CompareValidator>
</td>
</tr>
<tr>
<tdcolspan="2">
<asp:LiteralID="ErrorMessage"runat="server"EnableViewState="False"></asp:Literal>
</td>
</tr>
</table>
<asp:SqlDataSourceID="InsertExtraInfo"runat="server"ConnectionString="<%$ ConnectionStrings:ASPNETDBConnectionString1 %>"
InsertCommand="INSERT INTO [UserAddresses] ([UserId], [BillingAddress], [BillingCity], [BillingState], [BillingZip], [ShippingAddress], [ShippingCity], [ShippingState], [ShippingZip]) VALUES (@UserId, @BillingAddress, @BillingCity, @BillingState, @BillingZip, @ShippingAddress, @ShippingCity, @ShippingState, @ShippingZip)"
ProviderName="<%$ ConnectionStrings:ASPNETDBConnectionString1.ProviderName %>">
<InsertParameters>
<asp:ControlParameterName="BillingAddress"Type="String"ControlID="BillingAddress"PropertyName="Text"/>
<asp:ControlParameterName="BillingCity"Type="String"ControlID="BillingCity"PropertyName="Text"/>
<asp:ControlParameterName="BillingState"Type="String"ControlID="BillingState"PropertyName="Text"/>
<asp:ControlParameterName="BillingZip"Type="String"ControlID="BillingZip"PropertyName="Text"/>
<asp:ControlParameterName="ShippingAddress"Type="String"ControlID="ShippingAddress"PropertyName="Text"/>
<asp:ControlParameterName="ShippingCity"Type="String"ControlID="ShippingCity"PropertyName="Text"/>
<asp:ControlParameterName="ShippingState"Type="String"ControlID="ShippingState"PropertyName="Text"/>
<asp:ControlParameterName="ShippingZip"Type="String"ControlID="ShippingZip"PropertyName="Text"/>
</InsertParameters>
</asp:SqlDataSource>
</ContentTemplate>
</asp:CreateUserWizardStep>
<asp:CompleteWizardStepID="CompleteWizardStep1"runat="server">
</asp:CompleteWizardStep>
</WizardSteps>
<NavigationButtonStyleBackColor="White"BorderColor="#CC9966"BorderStyle="Solid"
BorderWidth="1px"Font-Names="Verdana"ForeColor="#990000"/>
<HeaderStyleBackColor="#FFCC66"BorderColor="#FFFBD6"BorderStyle="Solid"BorderWidth="2px"
Font-Bold="True"Font-Size="0.9em"ForeColor="#333333"HorizontalAlign="Center"/>
<CreateUserButtonStyleBackColor="White"BorderColor="#CC9966"BorderStyle="Solid"
BorderWidth="1px"Font-Names="Verdana"ForeColor="#990000"/>
<ContinueButtonStyleBackColor="White"BorderColor="#CC9966"BorderStyle="Solid"
BorderWidth="1px"Font-Names="Verdana"ForeColor="#990000"/>
<SideBarStyleBackColor="#990000"Font-Size="0.9em"VerticalAlign="Top"/>
<TitleTextStyleBackColor="#990000"Font-Bold="True"ForeColor="White"/>
<SideBarButtonStyleForeColor="White"/>
</asp:CreateUserWizard>
</asp:Content>
This is the code I am including in the createprofile.aspx. vb code behind file
Code:
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
PartialPublicClass _Default
Inherits System.Web.UI.Page
ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As EventArgs)
EndSub
ProtectedSub CreateUserWizard1_CreatedUser(ByVal sender AsObject, ByVal e As EventArgs)
Dim UserNameTextBox As TextBox = DirectCast(CreateUserWizardStep2.ContentTemplateContainer.FindControl("UserName"), TextBox)
Dim DataSource As SqlDataSource = DirectCast(CreateUserWizardStep2.ContentTemplateContainer.FindControl("InsertExtraInfo"), SqlDataSource)
Dim User As MembershipUser = Membership.GetUser(UserNameTextBox.Text)
Dim UserGUID AsObject = User.ProviderUserKey
DataSource.InsertParameters.Add("UserId", UserGUID.ToString())
DataSource.Insert()
EndSub
EndClass
The problem in here seems to be that it doesn't recognise CreateUserWizardStep2 as being declared, even though I can see it is in the createprofile.aspx file.
|
|

February 22nd, 2009, 10:51 AM
|
|
Friend of Wrox
|
|
Join Date: Sep 2005
Posts: 166
Thanks: 2
Thanked 33 Times in 33 Posts
|
|
Your code pasted a bit funny, so I was sorting it out in visual studio, but I just noticed that your aspx page is inheriting from ApplicationName.CreateProfile, while the vb class is called _Default. This would cause CreateUserWizardStep2 to not be found as it can't match up the page and code behind controls.
Try changing the end of the top line of the aspx to Inherits="_Default" and let us know if you're still having problems.
Also you should use CodeFile="CreateProfile.aspx. vb", instead of CodeBehind="...", as CodeBehind was for .NET 1.1 and doesn't work with partial classes very well.
Phil
Last edited by philip_cole; February 22nd, 2009 at 11:00 AM..
|
|
The Following User Says Thank You to philip_cole For This Useful Post:
|
|
|
 |