Thursday, March 29, 2012
newbie: HTML controls vs Web controls
I am learning .NET 2.0. And I have a question: when to use web-controls and
when to use HTML controls?
/RAM/Hi,
R.A.M. wrote:
> Hello,
> I am learning .NET 2.0. And I have a question: when to use web-controls an
d
> when to use HTML controls?
> /RAM/
The System.Web.UI.HtmlControls namespace is for HTML controls, in the
sense that they are declared on the page using standard HTML tags, for
example "input", "select", "textarea", etc...
The System.Web.UI.WebControls namespace is for ASP.NET controls, which
are declared on the page with an "asp:" prefix, for example "asp:Checkbox".
The different is that in the first case, they're client-side controls.
You use them on the server in order to set attributes, scripts, etc...
which are executed on the client. In the second case, however, (and
while you can also influence the way they will be rendered on the
client), the events you wire them to are executed on the server
(involving a postback).
HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
It depends on what you are more comfortable with. If you come from Windows
application background, you will find that web controls are more friendly
and they are a less dramatic change from your previous experience.. If you
come from html background you will like html controls. As you master your
asp.net skills, you will likely lean more towards html controls as they give
you better control over client-side functionality.
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"R.A.M." <r_ahimsa_m@.poczta.onet.pl> wrote in message
news:ejgq05$8h1$1@.news.onet.pl...
> Hello,
> I am learning .NET 2.0. And I have a question: when to use web-controls
> and when to use HTML controls?
> /RAM/
>
newbie: HTML controls vs Web controls
I am learning .NET 2.0. And I have a question: when to use web-controls and
when to use HTML controls?
/RAM/Hi,
R.A.M. wrote:
Quote:
Originally Posted by
Hello,
I am learning .NET 2.0. And I have a question: when to use web-controls and
when to use HTML controls?
/RAM/
The System.Web.UI.HtmlControls namespace is for HTML controls, in the
sense that they are declared on the page using standard HTML tags, for
example "input", "select", "textarea", etc...
The System.Web.UI.WebControls namespace is for ASP.NET controls, which
are declared on the page with an "asp:" prefix, for example "asp:Checkbox".
The different is that in the first case, they're client-side controls.
You use them on the server in order to set attributes, scripts, etc...
which are executed on the client. In the second case, however, (and
while you can also influence the way they will be rendered on the
client), the events you wire them to are executed on the server
(involving a postback).
HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
It depends on what you are more comfortable with. If you come from Windows
application background, you will find that web controls are more friendly
and they are a less dramatic change from your previous experience.. If you
come from html background you will like html controls. As you master your
asp.net skills, you will likely lean more towards html controls as they give
you better control over client-side functionality.
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"R.A.M." <r_ahimsa_m@.poczta.onet.plwrote in message
news:ejgq05$8h1$1@.news.onet.pl...
Quote:
Originally Posted by
Hello,
I am learning .NET 2.0. And I have a question: when to use web-controls
and when to use HTML controls?
/RAM/
>
Monday, March 26, 2012
NEWBIE: problem populating a GridView
I have a GridView control in my webpage. In this GridView's
gridUsers_RowDataBound am I having problem populating the controls with info
from the datasource -
This code is the problem:
MembershipUser user = (MembershipUser)e.Row.DataItem;
The user object doesn't get a MembershipUser value, it gets the value NULL.
Here are some of the code from my webpage so can get an overview of what I'm
doing:
<asp:GridView ID="gridUsers"
runat="server"
AutoGenerateColumns="false"
OnRowDataBound="gridUsers_RowDataBound" >
protected void Page_Load(object sender, EventArgs e)
{
MembershipUserCollection allUsers = Membership.GetAllUsers();
gridUsers.DataSource = allUsers;
gridUsers.DataBind();
}
protected void gridUsers_RowDataBound(object o, GridViewRowEventArgs e)
{
MembershipUser user = (MembershipUser)e.Row.DataItem; **** < this code
don't work
ProfileCommon userProfile = Profile.GetProfile(user.UserName);
/*
Here I will put code that manually populate the columns in the
GridView with info from the Profile object
*/
}
any suggestions on what I should do to populate the user object with the
MembershipUser value?
JeffFixed, I had forgotten this if statement:
if (e.Row.RowType == DataControlRowType.DataRow)
"Jeff" <it_consultant1@.hotmail.com.NOSPAM> wrote in message
news:eXxSBdzWHHA.4860@.TK2MSFTNGP04.phx.gbl...
> ASP.NET 2.0
> I have a GridView control in my webpage. In this GridView's
> gridUsers_RowDataBound am I having problem populating the controls with
> info from the datasource -
> This code is the problem:
> MembershipUser user = (MembershipUser)e.Row.DataItem;
> The user object doesn't get a MembershipUser value, it gets the value
> NULL.
> Here are some of the code from my webpage so can get an overview of what
> I'm doing:
> <asp:GridView ID="gridUsers"
> runat="server"
> AutoGenerateColumns="false"
> OnRowDataBound="gridUsers_RowDataBound" >
> protected void Page_Load(object sender, EventArgs e)
> {
> MembershipUserCollection allUsers = Membership.GetAllUsers();
> gridUsers.DataSource = allUsers;
> gridUsers.DataBind();
> }
> protected void gridUsers_RowDataBound(object o, GridViewRowEventArgs e)
> {
> MembershipUser user = (MembershipUser)e.Row.DataItem; **** < this code
> don't work
> ProfileCommon userProfile = Profile.GetProfile(user.UserName);
> /*
> Here I will put code that manually populate the columns in the
> GridView with info from the Profile object
> */
> }
> any suggestions on what I should do to populate the user object with the
> MembershipUser value?
> Jeff
>
NEWBIE: problem populating a GridView
I have a GridView control in my webpage. In this GridView's
gridUsers_RowDataBound am I having problem populating the controls with info
from the datasource -
This code is the problem:
MembershipUser user = (MembershipUser)e.Row.DataItem;
The user object doesn't get a MembershipUser value, it gets the value NULL.
Here are some of the code from my webpage so can get an overview of what I'm
doing:
<asp:GridView ID="gridUsers"
runat="server"
AutoGenerateColumns="false"
OnRowDataBound="gridUsers_RowDataBound" >
protected void Page_Load(object sender, EventArgs e)
{
MembershipUserCollection allUsers = Membership.GetAllUsers();
gridUsers.DataSource = allUsers;
gridUsers.DataBind();
}
protected void gridUsers_RowDataBound(object o, GridViewRowEventArgs e)
{
MembershipUser user = (MembershipUser)e.Row.DataItem; **** < this code
don't work
ProfileCommon userProfile = Profile.GetProfile(user.UserName);
/*
Here I will put code that manually populate the columns in the
GridView with info from the Profile object
*/
}
any suggestions on what I should do to populate the user object with the
MembershipUser value?
JeffFixed, I had forgotten this if statement:
if (e.Row.RowType == DataControlRowType.DataRow)
"Jeff" <it_consultant1@.hotmail.com.NOSPAMwrote in message
news:eXxSBdzWHHA.4860@.TK2MSFTNGP04.phx.gbl...
Quote:
Originally Posted by
ASP.NET 2.0
>
I have a GridView control in my webpage. In this GridView's
gridUsers_RowDataBound am I having problem populating the controls with
info from the datasource -
>
This code is the problem:
MembershipUser user = (MembershipUser)e.Row.DataItem;
The user object doesn't get a MembershipUser value, it gets the value
NULL.
>
Here are some of the code from my webpage so can get an overview of what
I'm doing:
<asp:GridView ID="gridUsers"
runat="server"
AutoGenerateColumns="false"
OnRowDataBound="gridUsers_RowDataBound" >
>
protected void Page_Load(object sender, EventArgs e)
{
MembershipUserCollection allUsers = Membership.GetAllUsers();
gridUsers.DataSource = allUsers;
gridUsers.DataBind();
}
>
protected void gridUsers_RowDataBound(object o, GridViewRowEventArgs e)
{
MembershipUser user = (MembershipUser)e.Row.DataItem; **** < this code
don't work
ProfileCommon userProfile = Profile.GetProfile(user.UserName);
/*
Here I will put code that manually populate the columns in the
GridView with info from the Profile object
*/
}
>
any suggestions on what I should do to populate the user object with the
MembershipUser value?
>
Jeff
>
newbie: Problems creating asp.net 2.0 Menu
ASP.NET 2.0
On my web page I got 2 menu controls: menu A is a horizontal menu displaying
menuitems at the top level. Menu B displays the submenuitems related to what
is selected in menu A. Menu A and Menu B are using the same sitemap
provider.. This works fine today.
But now I want to improve this a bit:
I still want menu B to show submenuitems related to menu A.. but now I also
want it show some other submenuitems which isn't affect by what is selected
in menu A
Example:
SideMenu
Item A
Item B
Item C
SideMenu B
Item D
Item E
Item F
In the example above SideMenu is related to what select in menu A, but
SideMenu B and it's submenuitems isn't related to menu A...
Here is the content of a sitemap file from my project:
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="Default.aspx" title="Home" description="">
<siteMapNode url="#" title="Main Menu A" description="" >
<siteMapNode url="#" title="Sub Menu 1" description="" />
<siteMapNode url="#" title="Sub Menu 2" description="" />
</siteMapNode>
<siteMapNode url="#" title="Main Menu B" description="" >
<siteMapNode url="#" title="Sub Menu 3" description="" />
<siteMapNode url="#" title="Sub Menu 4" description="" />
</siteMapNode>
</siteMapNode>
</siteMap>
This is the menu B markup in my web page:
<asp:Menu ID="mnuHeader"
runat="server"
DataSourceID="smdsHeader"
MaximumDynamicDisplayLevels="0"
Orientation="Horizontal"
StaticDisplayLevels="2"
OnMenuItemDataBound="mnuHeader_MenuItemDataBound"
StaticMenuItemStyle-CssClass="MainMenu"
StaticHoverStyle-CssClass="MainMenu:hover" />
<asp:SiteMapDataSource ID="smdsHeader" runat="server"
SiteMapProvider="Members" />
I'm wondering about how to configure (both in .sitemap file and in markup)
these additional submenu items so they are not related to what is selected
in menu A
Best Regards
JeffLook at the bottom
"Jeff" <it_consultant1@.hotmail.com.NOSPAMwrote in message
news:u7hIvCfTHHA.4668@.TK2MSFTNGP04.phx.gbl...
Quote:
Originally Posted by
Hey
>
ASP.NET 2.0
>
On my web page I got 2 menu controls: menu A is a horizontal menu
displaying menuitems at the top level. Menu B displays the submenuitems
related to what is selected in menu A. Menu A and Menu B are using the
same sitemap provider.. This works fine today.
>
But now I want to improve this a bit:
I still want menu B to show submenuitems related to menu A.. but now I
also want it show some other submenuitems which isn't affect by what is
selected in menu A
>
Example:
SideMenu
Item A
Item B
Item C
SideMenu B
Item D
Item E
Item F
>
In the example above SideMenu is related to what select in menu A, but
SideMenu B and it's submenuitems isn't related to menu A...
>
Here is the content of a sitemap file from my project:
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="Default.aspx" title="Home" description="">
<siteMapNode url="#" title="Main Menu A" description="" >
<siteMapNode url="#" title="Sub Menu 1" description="" />
<siteMapNode url="#" title="Sub Menu 2" description="" />
</siteMapNode>
<siteMapNode url="#" title="Main Menu B" description="" >
<siteMapNode url="#" title="Sub Menu 3" description="" />
<siteMapNode url="#" title="Sub Menu 4" description="" />
</siteMapNode>
</siteMapNode>
</siteMap>
>
This is the menu B markup in my web page:
<asp:Menu ID="mnuHeader"
runat="server"
DataSourceID="smdsHeader"
MaximumDynamicDisplayLevels="0"
Orientation="Horizontal"
StaticDisplayLevels="2"
OnMenuItemDataBound="mnuHeader_MenuItemDataBound"
StaticMenuItemStyle-CssClass="MainMenu"
StaticHoverStyle-CssClass="MainMenu:hover" />
<asp:SiteMapDataSource ID="smdsHeader" runat="server"
SiteMapProvider="Members" />
>
I'm wondering about how to configure (both in .sitemap file and in markup)
these additional submenu items so they are not related to what is selected
in menu A
>
Best Regards
>
Jeff
>
the menu markup I posted in my previous post is NOT for menu B it is for
menu A
Here is the markup of menu B:
<asp:Menu ID="mnuSidemenu"
runat="server"
DataSourceID="smdsHeader"
MaximumDynamicDisplayLevels="0"
Orientation="Vertical"
StaticDisplayLevels="2"
StaticMenuItemStyle-CssClass="menuitem"
StaticHoverStyle-CssClass="menuitem:hover"
OnMenuItemDataBound="mnuSidebar_MenuItemDataBound" >
</asp:Menu>
I still wondering how to solve this
Jeff
I've solved this by using 2 menu controls
"Jeff" <it_consultant1@.hotmail.com.NOSPAMwrote in message
news:OP2bkFfTHHA.996@.TK2MSFTNGP02.phx.gbl...
Quote:
Originally Posted by
Look at the bottom
>
"Jeff" <it_consultant1@.hotmail.com.NOSPAMwrote in message
news:u7hIvCfTHHA.4668@.TK2MSFTNGP04.phx.gbl...
Quote:
Originally Posted by
>Hey
>>
>ASP.NET 2.0
>>
>On my web page I got 2 menu controls: menu A is a horizontal menu
>displaying menuitems at the top level. Menu B displays the submenuitems
>related to what is selected in menu A. Menu A and Menu B are using the
>same sitemap provider.. This works fine today.
>>
>But now I want to improve this a bit:
>I still want menu B to show submenuitems related to menu A.. but now I
>also want it show some other submenuitems which isn't affect by what is
>selected in menu A
>>
>Example:
>SideMenu
> Item A
> Item B
> Item C
>SideMenu B
> Item D
> Item E
> Item F
>>
>In the example above SideMenu is related to what select in menu A, but
>SideMenu B and it's submenuitems isn't related to menu A...
>>
>Here is the content of a sitemap file from my project:
><?xml version="1.0" encoding="utf-8" ?>
><siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
> <siteMapNode url="Default.aspx" title="Home" description="">
> <siteMapNode url="#" title="Main Menu A" description="" >
> <siteMapNode url="#" title="Sub Menu 1" description="" />
> <siteMapNode url="#" title="Sub Menu 2" description="" />
> </siteMapNode>
> <siteMapNode url="#" title="Main Menu B" description="" >
> <siteMapNode url="#" title="Sub Menu 3" description="" />
> <siteMapNode url="#" title="Sub Menu 4" description="" />
> </siteMapNode>
> </siteMapNode>
></siteMap>
>>
>This is the menu B markup in my web page:
><asp:Menu ID="mnuHeader"
> runat="server"
> DataSourceID="smdsHeader"
> MaximumDynamicDisplayLevels="0"
> Orientation="Horizontal"
> StaticDisplayLevels="2"
> OnMenuItemDataBound="mnuHeader_MenuItemDataBound"
> StaticMenuItemStyle-CssClass="MainMenu"
> StaticHoverStyle-CssClass="MainMenu:hover" />
><asp:SiteMapDataSource ID="smdsHeader" runat="server"
>SiteMapProvider="Members" />
>>
>I'm wondering about how to configure (both in .sitemap file and in
>markup) these additional submenu items so they are not related to what is
>selected in menu A
>>
>Best Regards
>>
>Jeff
>>
>
the menu markup I posted in my previous post is NOT for menu B it is for
menu A
>
Here is the markup of menu B:
<asp:Menu ID="mnuSidemenu"
runat="server"
DataSourceID="smdsHeader"
MaximumDynamicDisplayLevels="0"
Orientation="Vertical"
StaticDisplayLevels="2"
StaticMenuItemStyle-CssClass="menuitem"
StaticHoverStyle-CssClass="menuitem:hover"
OnMenuItemDataBound="mnuSidebar_MenuItemDataBound" >
</asp:Menu>
>
I still wondering how to solve this
>
Jeff
>
I didn't find a solution so I had to use a workaround. Using 2 menu controls
instead of only 1
So I consider this thread for solved
"Jeff" <it_consultant1@.hotmail.com.NOSPAMwrote in message
news:OP2bkFfTHHA.996@.TK2MSFTNGP02.phx.gbl...
Quote:
Originally Posted by
Look at the bottom
>
"Jeff" <it_consultant1@.hotmail.com.NOSPAMwrote in message
news:u7hIvCfTHHA.4668@.TK2MSFTNGP04.phx.gbl...
Quote:
Originally Posted by
>Hey
>>
>ASP.NET 2.0
>>
>On my web page I got 2 menu controls: menu A is a horizontal menu
>displaying menuitems at the top level. Menu B displays the submenuitems
>related to what is selected in menu A. Menu A and Menu B are using the
>same sitemap provider.. This works fine today.
>>
>But now I want to improve this a bit:
>I still want menu B to show submenuitems related to menu A.. but now I
>also want it show some other submenuitems which isn't affect by what is
>selected in menu A
>>
>Example:
>SideMenu
> Item A
> Item B
> Item C
>SideMenu B
> Item D
> Item E
> Item F
>>
>In the example above SideMenu is related to what select in menu A, but
>SideMenu B and it's submenuitems isn't related to menu A...
>>
>Here is the content of a sitemap file from my project:
><?xml version="1.0" encoding="utf-8" ?>
><siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
> <siteMapNode url="Default.aspx" title="Home" description="">
> <siteMapNode url="#" title="Main Menu A" description="" >
> <siteMapNode url="#" title="Sub Menu 1" description="" />
> <siteMapNode url="#" title="Sub Menu 2" description="" />
> </siteMapNode>
> <siteMapNode url="#" title="Main Menu B" description="" >
> <siteMapNode url="#" title="Sub Menu 3" description="" />
> <siteMapNode url="#" title="Sub Menu 4" description="" />
> </siteMapNode>
> </siteMapNode>
></siteMap>
>>
>This is the menu B markup in my web page:
><asp:Menu ID="mnuHeader"
> runat="server"
> DataSourceID="smdsHeader"
> MaximumDynamicDisplayLevels="0"
> Orientation="Horizontal"
> StaticDisplayLevels="2"
> OnMenuItemDataBound="mnuHeader_MenuItemDataBound"
> StaticMenuItemStyle-CssClass="MainMenu"
> StaticHoverStyle-CssClass="MainMenu:hover" />
><asp:SiteMapDataSource ID="smdsHeader" runat="server"
>SiteMapProvider="Members" />
>>
>I'm wondering about how to configure (both in .sitemap file and in
>markup) these additional submenu items so they are not related to what is
>selected in menu A
>>
>Best Regards
>>
>Jeff
>>
>
the menu markup I posted in my previous post is NOT for menu B it is for
menu A
>
Here is the markup of menu B:
<asp:Menu ID="mnuSidemenu"
runat="server"
DataSourceID="smdsHeader"
MaximumDynamicDisplayLevels="0"
Orientation="Vertical"
StaticDisplayLevels="2"
StaticMenuItemStyle-CssClass="menuitem"
StaticHoverStyle-CssClass="menuitem:hover"
OnMenuItemDataBound="mnuSidebar_MenuItemDataBound" >
</asp:Menu>
>
I still wondering how to solve this
>
Jeff
>
Newbie: Question on web controls
I just downloaded webmatrix, tried an example, tested it, uploaded to my .NET enabled web site and it worked! I am impressed.
Questions: If I use more controls from the gallery or from webmatrix, do they need to be installed on my .NET enabled server? Do I have to request this to my web host ISP every time I use a new control? I am not clear on what services will I need from my web host ISP from time to time.
Thanks.No, fortunately for us Microsoft make asp.net not to have to "register" controls like you are saying. Good ole COM days had us doing that. Really all you need is to get that .dll that comes with the control, but it in your /bin directory of your application root, then all you have to do is reference and use it in your code. Pretty easy isn't it :)
--Michael
If you indeed use the Web Matrix-specific controls (such as the MxDataGrid), then you'll need to place a copy of Microsoft.Matrix.Framework.dll in your remote application's /bin folder.
You can find this DLL inside the folder for the Web Matrix. On my machine, it is:
c:\Program Files\Microsoft ASP.NET Web Matrix\v0.6.812\Framework\Microsoft.Matrix.Framework.dll
That's quite clear. Thansk to both of you.
Newbie: Propably simple answer Checkbox_checked?
I what to test a stored procedures on a web page using the normal connection
string.
the controls: Server, username,Password, database allow to select the
appropriate Sql server database.
Now I would use checkbox = Trusted connection as option to logon to the
database.
I guess the question that I have is where am I going wrong in the code?
How can I step through the script before or up until the page is loaded?
Any hints are greatly appreciated, the same will be made available after
completion.
Regards
Norman
Here is the Code:-----------------
<%@dotnet.itags.org. Page Language="VB" AutoEventWireup="True" %>
<%@dotnet.itags.org. import Namespace="System.Data" %>
<%@dotnet.itags.org. import Namespace="System.Data.SqlClient" %>
<%@dotnet.itags.org. import Namespace="System.Web.UI.WebControls" %>
<HTML>
<HEAD>
<script runat="server"
' code to check if the tickbox was ticked
Sub Check_Clicked(sender As Object, e As EventArgs)
If WinTrusted.checked then
'Dim conn As New SqlConnection( _
' "Data source=" & DatabaseServer.Text & _
' ";Trusted_Connection=true" & _
' ";Initial catalog=" & Database.Text)
'else
'Dim conn As New SqlConnection( _
' "Data source=" & DatabaseServer.Text & _
' ";Trusted_Connection=true" & _
' ";Initial catalog=" & Database.Text)
end if
End Sub
'
Sub LoginButton_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim ds As New DataSet
Dim conn As New SqlConnection( _
"Data source=" & DatabaseServer.Text & _
";Trusted_Connection=true" & _
";Initial catalog=" & Database.Text)
Dim cmd As New SqlCommand("sp_stored_procedures", conn) ' << when Sub
Check_Clicked and the code is run Asp courses an error at this line saying
that "conn" is not defined??
Dim adpt As New SqlDataAdapter(cmd)
Try
Status.Text = ""
adpt.Fill(ds, "SPs")
SPs.DataSource = ds.Tables("SPs")
SPs.DataTextField = "PROCEDURE_NAME"
SPs.DataBind()
Catch ex As SqlException
Status.Text = ex.Message
End Try
End Sub
Sub GetParametersButton_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim ds As New DataSet
'If Wintrusted.checked = True Then
' Dim conn As New SqlConnection( _
' "Data source=" & DatabaseServer.Text & _
' ";Trusted_Connection=true" & _
' ";Initial catalog=" & Database.Text)
'Else
Dim conn As New SqlConnection( _
"Data source=" & DatabaseServer.Text & _
";User id=" & Userid.text & _
";Password=" & Password.Text & _
";Initial catalog=" & Database.Text)
'End If
Dim cmd As New SqlCommand("sp_sproc_columns", conn) '' << when Sub
Check_Clicked and the code is run Asp courses an error at this line saying
that "conn" is not defined??
Dim adpt As New SqlDataAdapter(cmd)
Try
Status.Text = ""
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@dotnet.itags.org.procedure_name", SqlDbType.NVarchar, 390).Value = _
SPs.SelectedItem.Value
adpt.Fill(ds, "Parameters")
ParametersDataGrid.DataSource = ds.Tables("Parameters")
ParametersDataGrid.DataBind()
ResultsDataGrid.Visible = False
Catch ex As SqlException
Status.Text = ex.Message
End Try
End Sub
Sub AddParameters(ByVal cmd As SqlCommand)
'works ok
End Sub
Sub UpdateParameters(ByVal cmd As SqlCommand)
'Works Ok
End Sub
Sub ExecuteQueryButton_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim ds As New DataSet
'If WinTrusted.checked then
'Dim conn As New SqlConnection( _
' "Data source=" & DatabaseServer.Text & _
' ";Trusted_Connection=true" & _
' ";Initial catalog=" & Database.Text)
'else
Dim conn As New SqlConnection( _
"Data source=" & DatabaseServer.Text & _
";Trusted_Connection=true" & _
";Initial catalog=" & Database.Text)
'end if
Dim cmd As New SqlCommand(SPs.SelectedItem.Value, conn) ' ' << when Sub
Check_Clicked and the code is run Asp courses an error at this line saying
that "conn" is not defined??
Dim adpt As New SqlDataAdapter(cmd)
Try
Status.Text = ""
cmd.CommandType = CommandType.StoredProcedure
AddParameters(cmd)
adpt.Fill(ds, "Results")
UpdateParameters(cmd)
ResultsDataGrid.DataSource = ds.Tables("Results")
ResultsDataGrid.DataBind()
ResultsDataGrid.Visible = True
Catch ex As SqlException
Status.Text = ex.Message
End Try
End Sub
</script>
</HEAD>
----------End of
Code--------------You problem i think is happening because you are defining the connection in
a if statement
that would make it a local variable of
if(conditional statement)
{
// you code and your variables.
// any variables declared here are local to this if statement..
}
try
SqlConnection conn;
if(WinTrusted.checked == true)
con = new SqlConnection("con paramas")
else
con = new SqlConnection("second set of param")
}
SqlDataAdapter myCommand = new SqlDataAdapter("sp_storedproc", myCon)
myCommand.SelectCommand.CommandType = CommandType.StoredProc
This should work,
Hermit Dave
"Norman Fritag" <mtp.net@.ozemail.com.au> wrote in message
news:cY6Cb.10$Tq.1083@.nnrp1.ozemail.com.au...
> Hi there
> I what to test a stored procedures on a web page using the normal
connection
> string.
> the controls: Server, username,Password, database allow to select the
> appropriate Sql server database.
> Now I would use checkbox = Trusted connection as option to logon to the
> database.
> I guess the question that I have is where am I going wrong in the code?
> How can I step through the script before or up until the page is loaded?
> Any hints are greatly appreciated, the same will be made available after
> completion.
> Regards
> Norman
>
> Here is the Code:-----------------
> <%@. Page Language="VB" AutoEventWireup="True" %>
> <%@. import Namespace="System.Data" %>
> <%@. import Namespace="System.Data.SqlClient" %>
> <%@. import Namespace="System.Web.UI.WebControls" %>
> <HTML>
> <HEAD>
> <script runat="server">
> ' code to check if the tickbox was ticked
> Sub Check_Clicked(sender As Object, e As EventArgs)
> If WinTrusted.checked then
> 'Dim conn As New SqlConnection( _
> ' "Data source=" & DatabaseServer.Text & _
> ' ";Trusted_Connection=true" & _
> ' ";Initial catalog=" & Database.Text)
> 'else
> 'Dim conn As New SqlConnection( _
> ' "Data source=" & DatabaseServer.Text & _
> ' ";Trusted_Connection=true" & _
> ' ";Initial catalog=" & Database.Text)
> end if
> End Sub
> '
> Sub LoginButton_Click(ByVal sender As Object, ByVal e As EventArgs)
> Dim ds As New DataSet
> Dim conn As New SqlConnection( _
> "Data source=" & DatabaseServer.Text & _
> ";Trusted_Connection=true" & _
> ";Initial catalog=" & Database.Text)
> Dim cmd As New SqlCommand("sp_stored_procedures", conn) ' << when Sub
> Check_Clicked and the code is run Asp courses an error at this line saying
> that "conn" is not defined??
> Dim adpt As New SqlDataAdapter(cmd)
> Try
> Status.Text = ""
> adpt.Fill(ds, "SPs")
> SPs.DataSource = ds.Tables("SPs")
> SPs.DataTextField = "PROCEDURE_NAME"
> SPs.DataBind()
> Catch ex As SqlException
> Status.Text = ex.Message
> End Try
> End Sub
> Sub GetParametersButton_Click(ByVal sender As Object, ByVal e As
EventArgs)
> Dim ds As New DataSet
> 'If Wintrusted.checked = True Then
> ' Dim conn As New SqlConnection( _
> ' "Data source=" & DatabaseServer.Text & _
> ' ";Trusted_Connection=true" & _
> ' ";Initial catalog=" & Database.Text)
> 'Else
> Dim conn As New SqlConnection( _
> "Data source=" & DatabaseServer.Text & _
> ";User id=" & Userid.text & _
> ";Password=" & Password.Text & _
> ";Initial catalog=" & Database.Text)
> 'End If
> Dim cmd As New SqlCommand("sp_sproc_columns", conn) '' << when Sub
> Check_Clicked and the code is run Asp courses an error at this line saying
> that "conn" is not defined??
> Dim adpt As New SqlDataAdapter(cmd)
> Try
> Status.Text = ""
> cmd.CommandType = CommandType.StoredProcedure
> cmd.Parameters.Add("@.procedure_name", SqlDbType.NVarchar, 390).Value = _
> SPs.SelectedItem.Value
> adpt.Fill(ds, "Parameters")
> ParametersDataGrid.DataSource = ds.Tables("Parameters")
> ParametersDataGrid.DataBind()
> ResultsDataGrid.Visible = False
> Catch ex As SqlException
> Status.Text = ex.Message
> End Try
> End Sub
> Sub AddParameters(ByVal cmd As SqlCommand)
> 'works ok
> End Sub
> Sub UpdateParameters(ByVal cmd As SqlCommand)
> 'Works Ok
> End Sub
> Sub ExecuteQueryButton_Click(ByVal sender As Object, ByVal e As EventArgs)
> Dim ds As New DataSet
> 'If WinTrusted.checked then
> 'Dim conn As New SqlConnection( _
> ' "Data source=" & DatabaseServer.Text & _
> ' ";Trusted_Connection=true" & _
> ' ";Initial catalog=" & Database.Text)
> 'else
> Dim conn As New SqlConnection( _
> "Data source=" & DatabaseServer.Text & _
> ";Trusted_Connection=true" & _
> ";Initial catalog=" & Database.Text)
> 'end if
> Dim cmd As New SqlCommand(SPs.SelectedItem.Value, conn) ' ' << when Sub
> Check_Clicked and the code is run Asp courses an error at this line saying
> that "conn" is not defined??
> Dim adpt As New SqlDataAdapter(cmd)
> Try
> Status.Text = ""
> cmd.CommandType = CommandType.StoredProcedure
> AddParameters(cmd)
> adpt.Fill(ds, "Results")
> UpdateParameters(cmd)
> ResultsDataGrid.DataSource = ds.Tables("Results")
> ResultsDataGrid.DataBind()
> ResultsDataGrid.Visible = True
> Catch ex As SqlException
> Status.Text = ex.Message
> End Try
> End Sub
> </script>
> </HEAD>
> ----------End of
> Code--------------
Sorry bout the typos... too knackered... and too hungry and i would do with
some food and some sleep...
Your problem i think is happening because you are defining the connection in
a if statement
that would make it a local variable of
if(conditional statement)
{
// you code and your variables.
// any variables declared here are local to this if statement..
}
try
SqlConnection conn;
if(WinTrusted.checked == true)
conn = new SqlConnection("con paramas")
else
conn = new SqlConnection("second set of param")
}
SqlDataAdapter myCommand = new SqlDataAdapter("sp_storedproc", conn)
myCommand.SelectCommand.CommandType = CommandType.StoredProc
This should work,
Hermit Dave
"Hermit Dave" <hermitd.REMOVE@.CAPS.AND.DOTS.hotmail.com> wrote in message
news:evdi6$DwDHA.2372@.TK2MSFTNGP09.phx.gbl...
> You problem i think is happening because you are defining the connection
in
> a if statement
> that would make it a local variable of
> if(conditional statement)
> {
> // you code and your variables.
> // any variables declared here are local to this if statement..
> }
> try
> SqlConnection conn;
> if(WinTrusted.checked == true)
> con = new SqlConnection("con paramas")
> else
> con = new SqlConnection("second set of param")
> }
> SqlDataAdapter myCommand = new SqlDataAdapter("sp_storedproc", myCon)
> myCommand.SelectCommand.CommandType = CommandType.StoredProc
> This should work,
> Hermit Dave
> "Norman Fritag" <mtp.net@.ozemail.com.au> wrote in message
> news:cY6Cb.10$Tq.1083@.nnrp1.ozemail.com.au...
> > Hi there
> > I what to test a stored procedures on a web page using the normal
> connection
> > string.
> > the controls: Server, username,Password, database allow to select the
> > appropriate Sql server database.
> > Now I would use checkbox = Trusted connection as option to logon to the
> > database.
> > I guess the question that I have is where am I going wrong in the code?
> > How can I step through the script before or up until the page is loaded?
> > Any hints are greatly appreciated, the same will be made available after
> > completion.
> > Regards
> > Norman
> > Here is the Code:-----------------
> > <%@. Page Language="VB" AutoEventWireup="True" %>
> > <%@. import Namespace="System.Data" %>
> > <%@. import Namespace="System.Data.SqlClient" %>
> > <%@. import Namespace="System.Web.UI.WebControls" %>
> > <HTML>
> > <HEAD>
> > <script runat="server">
> > ' code to check if the tickbox was ticked
> > Sub Check_Clicked(sender As Object, e As EventArgs)
> > If WinTrusted.checked then
> > 'Dim conn As New SqlConnection( _
> > ' "Data source=" & DatabaseServer.Text & _
> > ' ";Trusted_Connection=true" & _
> > ' ";Initial catalog=" & Database.Text)
> > 'else
> > 'Dim conn As New SqlConnection( _
> > ' "Data source=" & DatabaseServer.Text & _
> > ' ";Trusted_Connection=true" & _
> > ' ";Initial catalog=" & Database.Text)
> > end if
> > End Sub
> > '
> > Sub LoginButton_Click(ByVal sender As Object, ByVal e As EventArgs)
> > Dim ds As New DataSet
> > Dim conn As New SqlConnection( _
> > "Data source=" & DatabaseServer.Text & _
> > ";Trusted_Connection=true" & _
> > ";Initial catalog=" & Database.Text)
> > Dim cmd As New SqlCommand("sp_stored_procedures", conn) ' << when Sub
> > Check_Clicked and the code is run Asp courses an error at this line
saying
> > that "conn" is not defined??
> > Dim adpt As New SqlDataAdapter(cmd)
> > Try
> > Status.Text = ""
> > adpt.Fill(ds, "SPs")
> > SPs.DataSource = ds.Tables("SPs")
> > SPs.DataTextField = "PROCEDURE_NAME"
> > SPs.DataBind()
> > Catch ex As SqlException
> > Status.Text = ex.Message
> > End Try
> > End Sub
> > Sub GetParametersButton_Click(ByVal sender As Object, ByVal e As
> EventArgs)
> > Dim ds As New DataSet
> > 'If Wintrusted.checked = True Then
> > ' Dim conn As New SqlConnection( _
> > ' "Data source=" & DatabaseServer.Text & _
> > ' ";Trusted_Connection=true" & _
> > ' ";Initial catalog=" & Database.Text)
> > 'Else
> > Dim conn As New SqlConnection( _
> > "Data source=" & DatabaseServer.Text & _
> > ";User id=" & Userid.text & _
> > ";Password=" & Password.Text & _
> > ";Initial catalog=" & Database.Text)
> > 'End If
> > Dim cmd As New SqlCommand("sp_sproc_columns", conn) '' << when Sub
> > Check_Clicked and the code is run Asp courses an error at this line
saying
> > that "conn" is not defined??
> > Dim adpt As New SqlDataAdapter(cmd)
> > Try
> > Status.Text = ""
> > cmd.CommandType = CommandType.StoredProcedure
> > cmd.Parameters.Add("@.procedure_name", SqlDbType.NVarchar, 390).Value = _
> > SPs.SelectedItem.Value
> > adpt.Fill(ds, "Parameters")
> > ParametersDataGrid.DataSource = ds.Tables("Parameters")
> > ParametersDataGrid.DataBind()
> > ResultsDataGrid.Visible = False
> > Catch ex As SqlException
> > Status.Text = ex.Message
> > End Try
> > End Sub
> > Sub AddParameters(ByVal cmd As SqlCommand)
> > 'works ok
> > End Sub
> > Sub UpdateParameters(ByVal cmd As SqlCommand)
> > 'Works Ok
> > End Sub
> > Sub ExecuteQueryButton_Click(ByVal sender As Object, ByVal e As
EventArgs)
> > Dim ds As New DataSet
> > 'If WinTrusted.checked then
> > 'Dim conn As New SqlConnection( _
> > ' "Data source=" & DatabaseServer.Text & _
> > ' ";Trusted_Connection=true" & _
> > ' ";Initial catalog=" & Database.Text)
> > 'else
> > Dim conn As New SqlConnection( _
> > "Data source=" & DatabaseServer.Text & _
> > ";Trusted_Connection=true" & _
> > ";Initial catalog=" & Database.Text)
> > 'end if
> > Dim cmd As New SqlCommand(SPs.SelectedItem.Value, conn) ' ' << when Sub
> > Check_Clicked and the code is run Asp courses an error at this line
saying
> > that "conn" is not defined??
> > Dim adpt As New SqlDataAdapter(cmd)
> > Try
> > Status.Text = ""
> > cmd.CommandType = CommandType.StoredProcedure
> > AddParameters(cmd)
> > adpt.Fill(ds, "Results")
> > UpdateParameters(cmd)
> > ResultsDataGrid.DataSource = ds.Tables("Results")
> > ResultsDataGrid.DataBind()
> > ResultsDataGrid.Visible = True
> > Catch ex As SqlException
> > Status.Text = ex.Message
> > End Try
> > End Sub
> > </script>
> > </HEAD>
> > ----------End of
> > Code--------------
Thanks Hermit Dave
I picked up the thought an it works Ok.
Regards
Norman
"Hermit Dave" <hermitd.REMOVE@.CAPS.AND.DOTS.hotmail.com> wrote in message
news:evdi6$DwDHA.2372@.TK2MSFTNGP09.phx.gbl...
> You problem i think is happening because you are defining the connection
in
> a if statement
> that would make it a local variable of
> if(conditional statement)
> {
> // you code and your variables.
> // any variables declared here are local to this if statement..
> }
> try
> SqlConnection conn;
> if(WinTrusted.checked == true)
> con = new SqlConnection("con paramas")
> else
> con = new SqlConnection("second set of param")
> }
> SqlDataAdapter myCommand = new SqlDataAdapter("sp_storedproc", myCon)
> myCommand.SelectCommand.CommandType = CommandType.StoredProc
> This should work,
> Hermit Dave
> "Norman Fritag" <mtp.net@.ozemail.com.au> wrote in message
> news:cY6Cb.10$Tq.1083@.nnrp1.ozemail.com.au...
> > Hi there
> > I what to test a stored procedures on a web page using the normal
> connection
> > string.
> > the controls: Server, username,Password, database allow to select the
> > appropriate Sql server database.
> > Now I would use checkbox = Trusted connection as option to logon to the
> > database.
> > I guess the question that I have is where am I going wrong in the code?
> > How can I step through the script before or up until the page is loaded?
> > Any hints are greatly appreciated, the same will be made available after
> > completion.
> > Regards
> > Norman
> > Here is the Code:-----------------
> > <%@. Page Language="VB" AutoEventWireup="True" %>
> > <%@. import Namespace="System.Data" %>
> > <%@. import Namespace="System.Data.SqlClient" %>
> > <%@. import Namespace="System.Web.UI.WebControls" %>
> > <HTML>
> > <HEAD>
> > <script runat="server">
> > ' code to check if the tickbox was ticked
> > Sub Check_Clicked(sender As Object, e As EventArgs)
> > If WinTrusted.checked then
> > 'Dim conn As New SqlConnection( _
> > ' "Data source=" & DatabaseServer.Text & _
> > ' ";Trusted_Connection=true" & _
> > ' ";Initial catalog=" & Database.Text)
> > 'else
> > 'Dim conn As New SqlConnection( _
> > ' "Data source=" & DatabaseServer.Text & _
> > ' ";Trusted_Connection=true" & _
> > ' ";Initial catalog=" & Database.Text)
> > end if
> > End Sub
> > '
> > Sub LoginButton_Click(ByVal sender As Object, ByVal e As EventArgs)
> > Dim ds As New DataSet
> > Dim conn As New SqlConnection( _
> > "Data source=" & DatabaseServer.Text & _
> > ";Trusted_Connection=true" & _
> > ";Initial catalog=" & Database.Text)
> > Dim cmd As New SqlCommand("sp_stored_procedures", conn) ' << when Sub
> > Check_Clicked and the code is run Asp courses an error at this line
saying
> > that "conn" is not defined??
> > Dim adpt As New SqlDataAdapter(cmd)
> > Try
> > Status.Text = ""
> > adpt.Fill(ds, "SPs")
> > SPs.DataSource = ds.Tables("SPs")
> > SPs.DataTextField = "PROCEDURE_NAME"
> > SPs.DataBind()
> > Catch ex As SqlException
> > Status.Text = ex.Message
> > End Try
> > End Sub
> > Sub GetParametersButton_Click(ByVal sender As Object, ByVal e As
> EventArgs)
> > Dim ds As New DataSet
> > 'If Wintrusted.checked = True Then
> > ' Dim conn As New SqlConnection( _
> > ' "Data source=" & DatabaseServer.Text & _
> > ' ";Trusted_Connection=true" & _
> > ' ";Initial catalog=" & Database.Text)
> > 'Else
> > Dim conn As New SqlConnection( _
> > "Data source=" & DatabaseServer.Text & _
> > ";User id=" & Userid.text & _
> > ";Password=" & Password.Text & _
> > ";Initial catalog=" & Database.Text)
> > 'End If
> > Dim cmd As New SqlCommand("sp_sproc_columns", conn) '' << when Sub
> > Check_Clicked and the code is run Asp courses an error at this line
saying
> > that "conn" is not defined??
> > Dim adpt As New SqlDataAdapter(cmd)
> > Try
> > Status.Text = ""
> > cmd.CommandType = CommandType.StoredProcedure
> > cmd.Parameters.Add("@.procedure_name", SqlDbType.NVarchar, 390).Value = _
> > SPs.SelectedItem.Value
> > adpt.Fill(ds, "Parameters")
> > ParametersDataGrid.DataSource = ds.Tables("Parameters")
> > ParametersDataGrid.DataBind()
> > ResultsDataGrid.Visible = False
> > Catch ex As SqlException
> > Status.Text = ex.Message
> > End Try
> > End Sub
> > Sub AddParameters(ByVal cmd As SqlCommand)
> > 'works ok
> > End Sub
> > Sub UpdateParameters(ByVal cmd As SqlCommand)
> > 'Works Ok
> > End Sub
> > Sub ExecuteQueryButton_Click(ByVal sender As Object, ByVal e As
EventArgs)
> > Dim ds As New DataSet
> > 'If WinTrusted.checked then
> > 'Dim conn As New SqlConnection( _
> > ' "Data source=" & DatabaseServer.Text & _
> > ' ";Trusted_Connection=true" & _
> > ' ";Initial catalog=" & Database.Text)
> > 'else
> > Dim conn As New SqlConnection( _
> > "Data source=" & DatabaseServer.Text & _
> > ";Trusted_Connection=true" & _
> > ";Initial catalog=" & Database.Text)
> > 'end if
> > Dim cmd As New SqlCommand(SPs.SelectedItem.Value, conn) ' ' << when Sub
> > Check_Clicked and the code is run Asp courses an error at this line
saying
> > that "conn" is not defined??
> > Dim adpt As New SqlDataAdapter(cmd)
> > Try
> > Status.Text = ""
> > cmd.CommandType = CommandType.StoredProcedure
> > AddParameters(cmd)
> > adpt.Fill(ds, "Results")
> > UpdateParameters(cmd)
> > ResultsDataGrid.DataSource = ds.Tables("Results")
> > ResultsDataGrid.DataBind()
> > ResultsDataGrid.Visible = True
> > Catch ex As SqlException
> > Status.Text = ex.Message
> > End Try
> > End Sub
> > </script>
> > </HEAD>
> > ----------End of
> > Code--------------