Showing posts with label user. Show all posts
Showing posts with label user. Show all posts

Saturday, March 31, 2012

Trim Each textbox control - Repost

HI

I'm trying to iterate through all the textboxes on a webpage and trim
them for spaces.

i.e. If a user enters " hello world " we correct it to "hello
world"

So far I've come up with this:

------------------------

'Trim all textboxes
Dim ThisControl As System.Web.UI.Control
For Each ThisControl In Me.Controls

If ThisControl.GetType().ToString() =
"system.Web.UI.WebControls.TextBox" Then

ThisControl.text = Trim(ThisControl.text)
'Above line is wrong syntax, I want to trim the textbox here, but I'm
stuck! Please help...

End If

Next ThisControl

------------------------

The problem I have is not really with the trim function. It's the fact
that I cannot update the control text value. It won't allow the .text
property at all in this example because "thiscontrol" is not actually
aware that the control assigned to it is actually a textbox. Is there a
way to tell it it's a textbox so I can access this property, or is there
another way around this?

Can you help?

Many Thanks!

AlexHi,

here is an example how to loop through controls on the Page:
http://www.aspnet101.com/aspnet101/tips.aspx?id=97

If you want to access Text property, you need to have typed reference (cast
it to TextBox with CType and set the value to the property).

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke

"Alex Shirley" <postings@.alexshirley.com> wrote in message
news:e9704b08.0406280400.238ba501@.posting.google.c om...
> HI
> I'm trying to iterate through all the textboxes on a webpage and trim
> them for spaces.
> i.e. If a user enters " hello world " we correct it to "hello
> world"
> So far I've come up with this:
> -----------------------
--
> 'Trim all textboxes
> Dim ThisControl As System.Web.UI.Control
> For Each ThisControl In Me.Controls
> If ThisControl.GetType().ToString() =
> "system.Web.UI.WebControls.TextBox" Then
> ThisControl.text = Trim(ThisControl.text)
> 'Above line is wrong syntax, I want to trim the textbox here, but I'm
> stuck! Please help...
> End If
> Next ThisControl
> -----------------------
--
> The problem I have is not really with the trim function. It's the fact
> that I cannot update the control text value. It won't allow the .text
> property at all in this example because "thiscontrol" is not actually
> aware that the control assigned to it is actually a textbox. Is there a
> way to tell it it's a textbox so I can access this property, or is there
> another way around this?
>
> Can you help?
> Many Thanks!
> Alex
Thanks Teemu

However I'm still stuck with the casting the object I've discovered in
a for next loop to a textbox so I can access its properties in
VB/ASP.Net... dumb I know, but I've looked everywhere for an answer,
but obviously not in the right places!

So far I've got this code:

-----------

Dim ThisControl As System.Web.UI.Control
Dim txtControl As TextBox

For Each ThisControl In Me.Controls
If ThisControl.GetType().ToString() =
"system.Web.UI.WebControls.TextBox" Then
txtControl = CType(ThisControl, TextBox) ' am I casting this
correctly?
txtControl.Text = "I'vechanged" 'Doesn't work
End If
Next ThisControl

-----------

I tried ThisControl = CType(ThisControl, TextBox), but the properties
won't appear for thiscontrol.

Sorry but can you or somebody help in this casting so I can update or
get the text property?

Thanks

Alex

"Teemu Keiski" <joteke@.aspalliance.com> wrote in message news:<elLAShQXEHA.4064@.TK2MSFTNGP11.phx.gbl>...
> Hi,
> here is an example how to loop through controls on the Page:
> http://www.aspnet101.com/aspnet101/tips.aspx?id=97
> If you want to access Text property, you need to have typed reference (cast
> it to TextBox with CType and set the value to the property).
> --
> Teemu Keiski
> MCP, Microsoft MVP (ASP.NET), AspInsiders member
> ASP.NET Forum Moderator, AspAlliance Columnist
> http://blogs.aspadvice.com/joteke
> "Alex Shirley" <postings@.alexshirley.com> wrote in message
> news:e9704b08.0406280400.238ba501@.posting.google.c om...
> > HI
> > I'm trying to iterate through all the textboxes on a webpage and trim
> > them for spaces.
> > i.e. If a user enters " hello world " we correct it to "hello
> > world"
> > So far I've come up with this:
> > -----------------------
> --
> > 'Trim all textboxes
> > Dim ThisControl As System.Web.UI.Control
> > For Each ThisControl In Me.Controls
> > If ThisControl.GetType().ToString() =
> > "system.Web.UI.WebControls.TextBox" Then
> > ThisControl.text = Trim(ThisControl.text)
> > 'Above line is wrong syntax, I want to trim the textbox here, but I'm
> > stuck! Please help...
> > End If
> > Next ThisControl
> > -----------------------
> --
> > The problem I have is not really with the trim function. It's the fact
> > that I cannot update the control text value. It won't allow the .text
> > property at all in this example because "thiscontrol" is not actually
> > aware that the control assigned to it is actually a textbox. Is there a
> > way to tell it it's a textbox so I can access this property, or is there
> > another way around this?
> > Can you help?
> > Many Thanks!
> > Alex

Trim Each textbox control

HI
I'm trying to iterate through all the textboxes on a webpage and trim
them for spaces.
i.e. If a user enters " hello world " we correct it to "hello
world"
So far I've come up with this:
----
--
'Trim all textboxes
Dim ThisControl As System.Web.UI.Control
For Each ThisControl In Me.Controls
If ThisControl.GetType().ToString() =
"system.Web.UI.WebControls.TextBox" Then
ThisControl.text = Trim(ThisControl.text)
'Above line is wrong syntax, I want to trim the textbox here, but I'm
stuck! Please help...
End If
Next ThisControl
----
--
Can you help?
Many Thanks!
Alexuse RTrim() and LTrim().
R for right and L for the left side to remove spaces.
"Alex Shirley" <postings@.alexshirley.com> schreef in bericht
news:e9704b08.0406240318.6e352a45@.posting.google.com...
> HI
> I'm trying to iterate through all the textboxes on a webpage and trim
> them for spaces.
> i.e. If a user enters " hello world " we correct it to "hello
> world"
> So far I've come up with this:
> ----
--
> 'Trim all textboxes
> Dim ThisControl As System.Web.UI.Control
> For Each ThisControl In Me.Controls
> If ThisControl.GetType().ToString() =
> "system.Web.UI.WebControls.TextBox" Then
> ThisControl.text = Trim(ThisControl.text)
> 'Above line is wrong syntax, I want to trim the textbox here, but I'm
> stuck! Please help...
> End If
> Next ThisControl
> ----
--
> Can you help?
> Many Thanks!
> Alex
Hi Richard
The problem I have is not really with the trim function. It's the fact
that I cannot update the control text value. It won't allow the .text
property at all in this example because "thiscontrol" is not actually
aware that the control assigned to it is actually a textbox. Is there a
way to tell it it's a textbox so I can access this property, or is there
another way around this?
Any answers folks?
Cheers
Alex
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!

Trim Each textbox control

HI

I'm trying to iterate through all the textboxes on a webpage and trim
them for spaces.

i.e. If a user enters " hello world " we correct it to "hello
world"

So far I've come up with this:

------------------------

'Trim all textboxes
Dim ThisControl As System.Web.UI.Control
For Each ThisControl In Me.Controls

If ThisControl.GetType().ToString() =
"system.Web.UI.WebControls.TextBox" Then

ThisControl.text = Trim(ThisControl.text)
'Above line is wrong syntax, I want to trim the textbox here, but I'm
stuck! Please help...

End If

Next ThisControl

------------------------

Can you help?

Many Thanks!

Alexuse RTrim() and LTrim().
R for right and L for the left side to remove spaces.

"Alex Shirley" <postings@.alexshirley.com> schreef in bericht
news:e9704b08.0406240318.6e352a45@.posting.google.c om...
> HI
> I'm trying to iterate through all the textboxes on a webpage and trim
> them for spaces.
> i.e. If a user enters " hello world " we correct it to "hello
> world"
> So far I've come up with this:
> -----------------------
--
> 'Trim all textboxes
> Dim ThisControl As System.Web.UI.Control
> For Each ThisControl In Me.Controls
> If ThisControl.GetType().ToString() =
> "system.Web.UI.WebControls.TextBox" Then
> ThisControl.text = Trim(ThisControl.text)
> 'Above line is wrong syntax, I want to trim the textbox here, but I'm
> stuck! Please help...
> End If
> Next ThisControl
> -----------------------
--
> Can you help?
> Many Thanks!
> Alex
Hi Richard

The problem I have is not really with the trim function. It's the fact
that I cannot update the control text value. It won't allow the .text
property at all in this example because "thiscontrol" is not actually
aware that the control assigned to it is actually a textbox. Is there a
way to tell it it's a textbox so I can access this property, or is there
another way around this?

Any answers folks?

Cheers

Alex

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!

Trim Each textbox control - Repost

HI
I'm trying to iterate through all the textboxes on a webpage and trim
them for spaces.
i.e. If a user enters " hello world " we correct it to "hello
world"
So far I've come up with this:
----
--
'Trim all textboxes
Dim ThisControl As System.Web.UI.Control
For Each ThisControl In Me.Controls
If ThisControl.GetType().ToString() =
"system.Web.UI.WebControls.TextBox" Then
ThisControl.text = Trim(ThisControl.text)
'Above line is wrong syntax, I want to trim the textbox here, but I'm
stuck! Please help...
End If
Next ThisControl
----
--
The problem I have is not really with the trim function. It's the fact
that I cannot update the control text value. It won't allow the .text
property at all in this example because "thiscontrol" is not actually
aware that the control assigned to it is actually a textbox. Is there a
way to tell it it's a textbox so I can access this property, or is there
another way around this?
Can you help?
Many Thanks!
AlexHi,
here is an example how to loop through controls on the Page:
http://www.aspnet101.com/aspnet101/tips.aspx?id=97
If you want to access Text property, you need to have typed reference (cast
it to TextBox with CType and set the value to the property).
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke
"Alex Shirley" <postings@.alexshirley.com> wrote in message
news:e9704b08.0406280400.238ba501@.posting.google.com...
> HI
> I'm trying to iterate through all the textboxes on a webpage and trim
> them for spaces.
> i.e. If a user enters " hello world " we correct it to "hello
> world"
> So far I've come up with this:
> ----
--
> 'Trim all textboxes
> Dim ThisControl As System.Web.UI.Control
> For Each ThisControl In Me.Controls
> If ThisControl.GetType().ToString() =
> "system.Web.UI.WebControls.TextBox" Then
> ThisControl.text = Trim(ThisControl.text)
> 'Above line is wrong syntax, I want to trim the textbox here, but I'm
> stuck! Please help...
> End If
> Next ThisControl
> ----
--
> The problem I have is not really with the trim function. It's the fact
> that I cannot update the control text value. It won't allow the .text
> property at all in this example because "thiscontrol" is not actually
> aware that the control assigned to it is actually a textbox. Is there a
> way to tell it it's a textbox so I can access this property, or is there
> another way around this?
>
> Can you help?
> Many Thanks!
> Alex
Thanks Teemu
However I'm still stuck with the casting the object I've discovered in
a for next loop to a textbox so I can access its properties in
VB/ASP.Net... dumb I know, but I've looked everywhere for an answer,
but obviously not in the right places!
So far I've got this code:
Dim ThisControl As System.Web.UI.Control
Dim txtControl As TextBox
For Each ThisControl In Me.Controls
If ThisControl.GetType().ToString() =
"system.Web.UI.WebControls.TextBox" Then
txtControl = CType(ThisControl, TextBox) ' am I casting this
correctly?
txtControl.Text = "I'vechanged" 'Doesn't work
End If
Next ThisControl
I tried ThisControl = CType(ThisControl, TextBox), but the properties
won't appear for thiscontrol.
Sorry but can you or somebody help in this casting so I can update or
get the text property?
Thanks
Alex
"Teemu Keiski" <joteke@.aspalliance.com> wrote in message news:<elLAShQXEHA.4064@.TK2MSFTNGP1
1.phx.gbl>...
> Hi,
> here is an example how to loop through controls on the Page:
> http://www.aspnet101.com/aspnet101/tips.aspx?id=97
> If you want to access Text property, you need to have typed reference (cas
t
> it to TextBox with CType and set the value to the property).
> --
> Teemu Keiski
> MCP, Microsoft MVP (ASP.NET), AspInsiders member
> ASP.NET Forum Moderator, AspAlliance Columnist
> http://blogs.aspadvice.com/joteke
> "Alex Shirley" <postings@.alexshirley.com> wrote in message
> news:e9704b08.0406280400.238ba501@.posting.google.com...
> --
> --

Trim to a specific alphanumeric quotable

HI all,

I am using c# and I am trying to use the windows authentication to recognize the users.
(User.Identity.Name)

Unfortunately, the users will belong to different domains and there fore their identity will look different. i.e. domain\username or net\username.

How can I remove everything before the username including the backslash?

thank you in advance,

GorginioHave you looked into substring??

// psuedo code

userName = User.Identity.Name.SubString(User.Identity.Name.IndexOf("\"));

That may or may not work.
Welcome to the ASP.NET forums, Gorginio.

You can use the following code:

 // get the username ... but I'll fake it here
string fullUsername = @."domain\username";

// trim away any domain that may form part of the username
string trimmedUsername;
int indexOfSlash = fullUsername.IndexOf( @."\" );
if (indexOfSlash > -1)
{
trimmedUsername = fullUsername.Substring( indexOfSlash + 1, fullUsername.Length - indexOfSlash - 1 );
}
else
{
trimmedUsername = fullUsername;
}

I hope this helps.

Trim URL

Hi,
I am involved in designing a website in which on a certain page(that contains a form) if some message is to be shown to the user the URL looks like
http://myserver/somepage.aspx?message=.....
Now if on that page the user requests re-submits the form I want the URL to be trimmed as simply http://myserver/somepage.aspx

Also is there some way that I can send such error messages through some means(like POST) such that there is no change in the url.If yes plz elaborate on it

Cheers,
-Aayush

Why don't you pass the parameter into a session, so instead of passing ?message=.....

do

Session["message"] = "...";

and in the next page you do:

string message = Session["message"].ToString();

Session.Remove("message");


you can use server variables and retrieve the required info

Wednesday, March 28, 2012

Trimming text returned from db

Hi

In my App I have a datagrid with a template column. In my DB I have a field called "Bio" wich holds user biographies. The idea is that within the datagrid only a small portion of the bio is shown and visitors click onto detail pages to see photgraphs and full information. Is there a way to limit the output from the Bio field to say 100 characters

Thanks

hpYou could limit the size of what you display in your datagrid column for Bio through many ways. One of those is to limit what you fetch from the database using LEFT(Bio,100) in your SQL statement.

You could equally use a bound column. This is what MSDN has to say on that:

"A bound column (BoundColumn element) displays information from one column of a data source. You typically add one bound column to the grid for every data column you want to display. Use bound columns when you want to choose which data columns to display in the grid. Bound columns also allow you to set a variety of properties to specify features such as:

The text, font, and color of the column header and footer.
Column width.
Data format.

Whether the column is read-only (that is, whether it will display an editable control when the row is in edit mode).
For details on creating bound columns in the Visual Studio Web Forms Designer, see Adding Bound Columns to a DataGrid Web Server Control. For details on creating bound columns, see DataGrid Web Server Control."

You should be able to combine both approaches to evolve something nice.
In addition if you need the full bio from the db to use later one (perhaps they can vie the full bio via a link or something), you may want to just limit it on the front end. To do this you could use the ItemDataBound of the datagrid. If the value is stored in a control such as a lable you would use FindControl and then set the value. Something like this...

Label lblTemp = (Label)e.Item.FindControl("lblBio");
if (lblTemp != null)
lblTemp = lblTemp.Text.Substring(1, 100);

May not be completely accurate but it should get you on the right path.
Excellent, Many thanks

Trouble accessing .NET 2.0 Membership stuff from HTTP Module

I am trying to create an HTTP module to run on ASP.NET 2.0. The module needs
to check to see if the user is authenticated with the .net 2.0 membership
stuff. I am trying this:

If application.Context.User.Identity.IsAuthenticated Then
app.Context.Response.Write("user authenticated")
End If

I get a "Object Reference not set to an instance of anobject." error on
application.Context.User.Identity.IsAuthenticated.

I am always getting an error. Does anyone have any suggestions? Do I need
to configure anything special for the module? Thanks.You should look into handling the PostAuthenticateRequest event instead.
That way you don't have ordering issues with the other modules during the
AuthenticateRequest event.

-Brock
DevelopMentor
http://staff.develop.com/ballen

> I am trying to create an HTTP module to run on ASP.NET 2.0. The
> module needs to check to see if the user is authenticated with the
> .net 2.0 membership stuff. I am trying this:
> If application.Context.User.Identity.IsAuthenticated Then
> app.Context.Response.Write("user authenticated")
> End If
> I get a "Object Reference not set to an instance of anobject." error
> on application.Context.User.Identity.IsAuthenticated.
> I am always getting an error. Does anyone have any suggestions? Do I
> need to configure anything special for the module? Thanks.
Thanks. That fixed it.

"Brock Allen" wrote:

> You should look into handling the PostAuthenticateRequest event instead.
> That way you don't have ordering issues with the other modules during the
> AuthenticateRequest event.
> -Brock
> DevelopMentor
> http://staff.develop.com/ballen
>
> > I am trying to create an HTTP module to run on ASP.NET 2.0. The
> > module needs to check to see if the user is authenticated with the
> > .net 2.0 membership stuff. I am trying this:
> > If application.Context.User.Identity.IsAuthenticated Then
> > app.Context.Response.Write("user authenticated")
> > End If
> > I get a "Object Reference not set to an instance of anobject." error
> > on application.Context.User.Identity.IsAuthenticated.
> > I am always getting an error. Does anyone have any suggestions? Do I
> > need to configure anything special for the module? Thanks.
>
>

Trouble accessing object before insertion into panel...

Hey everyone,

I have a script that presents the user with a variable number of text boxes (with the ID's "TextBox1", "TextBox2", "TextBox3", etc.) with an image button, and a label asking the user for input. All this is contained in a panel called Panel1. The user puts some text into the boxes and clicks the image button.

When clicked, the image button raises an event that tries and access the text the user entered in the text boxes, assign that text to a label, and display it in Panel2. It will then hide Panel1 and make Panel2 visible. The event generates an error however. I don't understand the error because the code seems straight forward. Here is the code (intTxtCount contains the number of text boxes that the user was presented with):


Public Sub cmdContinueToDeparturePoints(Sender As Object, e As System.Web.UI.ImageClickEventArgs)

Dim i As Integer
For i = 1 To intTxtCount
Dim lblName As New Label()
lblName.ID = "lblName" & i
Dim txtTemp As TextBox
txtTemp = FindControl("TextBox" & i)
lblName.Text = txtTemp.Text '''' Error Generating Line
Panel2.Controls.Add(lblName)
Panel2.Controls.Add(New LiteralControl("<br>"))
Next i

Panel1.Visible = False
Panel2.Visible = True

End Sub


Here is the Error:

System.NullReferenceException: Object reference not set to an instance of an object.

I think this error is telling me that a control called lblName does not exist physically in my panel, which is true. But if I reference lblName the object (the one I just declared in the sub) shouldn't that be okay? Am I wrong?

Bewildering...Mike :-/1. NullReferenceException is one of the most common programming errors. So it will help to really learn it well. It means that an object that is being dereferenced (the object followed by a period) is 'null' or 'nothing' in VB terms.

In this line, there are two objects being dereferenced:
lblName.Text = txtTemp.Text

lblName is created just above and you dereferenced it when you assigned the ID. So that's not it. txtTemp is the result of FindControl. You are assuming that you will find a control with the ID "TextBox1" (or whatever number 'i' is when this fails). It is returning null at some point.

2. Its likely that you have not recreated the same list of TextBoxes on post back before this loop executes. Also consider that you have a loop maximum in variable that may not reflect the true number of textboxes.

3. If you are going to write code, please consider using a debugger. Single-step through code and review the values of variables, parameters, and properties as things happen. The debugger would stop on the line with the error and let you open a Watch or Local Variable window to see what the values are in lblName and txtTemp.
Peter,

Thanks for such a great response. Yes, I should be using a debugger. If only my company were not so cheap as to let me code without VisualStudio.NET... :-(

Ok. So we have managed to conclude that lblName is not generating the Null Exception. It must be that no value is being assigned to txtTemp.Text from "TextBox1". Your comments in line item number 2 really interest me:

What do you mean by, "you have not recreated the same list of TextBoxes on post back before this loop executes"? I have never had to "recreate" a form for a PostBack event. I don't even know what you mean by that. And as for the maximum loop variable, I am positive this value is correct every time the script runs. The HTML that the server generages clearly shows me the correct number of text boxes, all with the correct names (TextBox1, T...2, T...3, etc.). I don't understand why when this form is submitted and I try to assign the boxes values they are null. Just don't get it.

Here is some code that works fine, this is what I based my current work on:


Sub Page_Load(sender As Object, e As EventArgs)

Dim t As New TextBox()
Dim i As Integer = 1
t.Text = "testtext" & i.ToString()
t.ID = "myTextBox" & i.ToString()
Panel1.Controls.Add(t)
ViewState("i") = i

End Sub

Sub GetTextBoxValueAndAssignToLabel(sender As Object, e As System.EventArgs)

Dim i As Integer
i = ViewState("i")
Dim txtTemp As TextBox
txtTemp = FindControl("myTextBox" & i)
lblTest.Text = txtTemp.Text

End Sub


As you can see, a text box is created that has an ID of "myTextBox1". The number i is passed via ViewState to the event code for the button, and the Text property of the text box is successfully assigned to the label. As far as I can see, the only difference between my code and the code here is that the label control already exists in the form instead of the on-the-fly label creation I used.
Let's start with that darn debugger issue. My sympathies about your situation. The time you waste without a debugger will easily exceed the cost of VS.NET.

In the meantime, did you know that .net framework comes with a debugger? Lookup "DbgClr.exe" at MSDN.Microsoft.com. I have not used it though, since I'm using VS.NET.

On to your code. I'm confused by this, perhaps because you simplified it. I though you had a loop going on. I'm interested in that loop. For example, if you are assigning ViewState("i") = i in each interation of the loop, you are not changing the key passed to ViewState, and thus overwriting the value.

Please do this too: set <@.Page Trace=true >. When the page is first generated, it will show you each control by its ID. FindControl will only search in the "naming container" of that method. In this case, whatever object contains GetTextBoxValueAndAssignToLabel() is the naming container you are searching. If you did Panel1.FindControl, you will be assured of getting values from Panel1. Another thing you can do is simply grab each unique item in Panel1.Controls.
Panel1.Controls(0) - contains TextBox1
Panel1.Controls(1) - contains TextBox2

trouble connecting to remote SQL server for authentication

I've got an app which provides data based on the user who is logged in.
So, I need the user data to be on the same db server as the other
data. I'm trying to do this using the membership API. I've set up the
tables and sprocs and so forth using the aspnet_regsql.exe (though, for
some reason, I had to do it using windows authentication rather than
using a SQL server account). I've modified the web.config file as
follows
<?xml version="1.0" encoding="utf-8"?>
<configuration
xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<connectionStrings>
<add name="SLAR-con" connectionString="Data
Source=mySQLserver;Initial Catalog=SLAR;User
Id=mydomain\myuserid;Password=mypassword
" />
</connectionStrings>
<system.web>
<roleManager enabled="true" />
<authentication mode="Forms" />
<membership>
<providers>
<add connectionStringName="SLAR-con"
applicationName="SLAR" minRequiredPasswordLength="5"
minRequiredNonalphanumericCharacters="0"
name="CustomizedProvider"
type="System.Web.Security.SqlMembershipProvider" />
</providers>
</membership>
</system.web>
</configuration>
and I've tested the login and it seems to be working. However, when I
go into the database on the SQL server to look at the user I created,
the user authentication tables are all empty. The data isn't being
stored on the SQL server where I want it to be (I'm assuming it is
being stored in a SQL Server express database on the local machine).
How do I get the data to be stored in the remote SQL server?
----
--Check both databases and make sure it is not pointiong locally. As long as
machine name is correct, you should be on the other server.
NOTE: SQL Server 2005 requires SQL Browser on to connect remotely. You also
have to have proper transports set up, as some versions install without
TCP/IP or named pipes on.
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com
****************************************
*********
Think outside of the box!
****************************************
*********
<brian.newman@.wpafb.af.mil> wrote in message
news:1161862621.467371.69570@.i3g2000cwc.googlegroups.com...
> I've got an app which provides data based on the user who is logged in.
> So, I need the user data to be on the same db server as the other
> data. I'm trying to do this using the membership API. I've set up the
> tables and sprocs and so forth using the aspnet_regsql.exe (though, for
> some reason, I had to do it using windows authentication rather than
> using a SQL server account). I've modified the web.config file as
> follows
> <?xml version="1.0" encoding="utf-8"?>
> <configuration
> xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
> <connectionStrings>
> <add name="SLAR-con" connectionString="Data
> Source=mySQLserver;Initial Catalog=SLAR;User
> Id=mydomain\myuserid;Password=mypassword
" />
> </connectionStrings>
> <system.web>
> <roleManager enabled="true" />
> <authentication mode="Forms" />
> <membership>
> <providers>
> <add connectionStringName="SLAR-con"
> applicationName="SLAR" minRequiredPasswordLength="5"
> minRequiredNonalphanumericCharacters="0"
> name="CustomizedProvider"
> type="System.Web.Security.SqlMembershipProvider" />
> </providers>
> </membership>
>
> </system.web>
> </configuration>
> and I've tested the login and it seems to be working. However, when I
> go into the database on the SQL server to look at the user I created,
> the user authentication tables are all empty. The data isn't being
> stored on the SQL server where I want it to be (I'm assuming it is
> being stored in a SQL Server express database on the local machine).
> How do I get the data to be stored in the remote SQL server?
>
> ----
--
>
Cowboy (Gregory A. Beamer) wrote:
> Check both databases and make sure it is not pointiong locally. As long as
> machine name is correct, you should be on the other server.
> NOTE: SQL Server 2005 requires SQL Browser on to connect remotely. You als
o
> have to have proper transports set up, as some versions install without
> TCP/IP or named pipes on.
> --
> Gregory A. Beamer
> MVP; MCP: +I, SE, SD, DBA
> http://gregorybeamer.spaces.live.com
> ****************************************
*********
> Think outside of the box!
> ****************************************
*********
> <brian.newman@.wpafb.af.mil> wrote in message
> news:1161862621.467371.69570@.i3g2000cwc.googlegroups.com...
It is being stored locally (local to the machine on which I'm doing the
development), but I'm unclear on how to point it to the SQL server db.
I thought the edits shown in the top post I made to the web.config file
would handle that, but they don't. The SQL server db is SQL Server
2000.
By the way, thanks for the assist. I posted on Microsoft asp.net forum
and got 20 views, but no assist and got nothing from 4guysfromrolla.

trouble connecting to remote SQL server for authentication

I've got an app which provides data based on the user who is logged in.
So, I need the user data to be on the same db server as the other
data. I'm trying to do this using the membership API. I've set up the
tables and sprocs and so forth using the aspnet_regsql.exe (though, for
some reason, I had to do it using windows authentication rather than
using a SQL server account). I've modified the web.config file as
follows

<?xml version="1.0" encoding="utf-8"?>

<configuration
xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">

<connectionStrings>

<add name="SLAR-con" connectionString="Data
Source=mySQLserver;Initial Catalog=SLAR;User
Id=mydomain\myuserid;Password=mypassword" />

</connectionStrings>

<system.web>

<roleManager enabled="true" />

<authentication mode="Forms" />

<membership>

<providers>

<add connectionStringName="SLAR-con"
applicationName="SLAR" minRequiredPasswordLength="5"

minRequiredNonalphanumericCharacters="0"
name="CustomizedProvider"

type="System.Web.Security.SqlMembershipProvider" />

</providers>

</membership>

</system.web>

</configuration>

and I've tested the login and it seems to be working. However, when I
go into the database on the SQL server to look at the user I created,
the user authentication tables are all empty. The data isn't being
stored on the SQL server where I want it to be (I'm assuming it is
being stored in a SQL Server express database on the local machine).
How do I get the data to be stored in the remote SQL server?

------------------------Check both databases and make sure it is not pointiong locally. As long as
machine name is correct, you should be on the other server.

NOTE: SQL Server 2005 requires SQL Browser on to connect remotely. You also
have to have proper transports set up, as some versions install without
TCP/IP or named pipes on.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com
*************************************************
Think outside of the box!
*************************************************
<brian.newman@.wpafb.af.milwrote in message
news:1161862621.467371.69570@.i3g2000cwc.googlegrou ps.com...

Quote:

Originally Posted by

I've got an app which provides data based on the user who is logged in.
So, I need the user data to be on the same db server as the other
data. I'm trying to do this using the membership API. I've set up the
tables and sprocs and so forth using the aspnet_regsql.exe (though, for
some reason, I had to do it using windows authentication rather than
using a SQL server account). I've modified the web.config file as
follows
>
<?xml version="1.0" encoding="utf-8"?>
>
<configuration
xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
>
<connectionStrings>
>
<add name="SLAR-con" connectionString="Data
Source=mySQLserver;Initial Catalog=SLAR;User
Id=mydomain\myuserid;Password=mypassword" />
>
</connectionStrings>
>
<system.web>
>
<roleManager enabled="true" />
>
<authentication mode="Forms" />
>
<membership>
>
<providers>
>
<add connectionStringName="SLAR-con"
applicationName="SLAR" minRequiredPasswordLength="5"
>
minRequiredNonalphanumericCharacters="0"
name="CustomizedProvider"
>
type="System.Web.Security.SqlMembershipProvider" />
>
</providers>
>
</membership>
>
>
>
</system.web>
>
</configuration>
>
and I've tested the login and it seems to be working. However, when I
go into the database on the SQL server to look at the user I created,
the user authentication tables are all empty. The data isn't being
stored on the SQL server where I want it to be (I'm assuming it is
being stored in a SQL Server express database on the local machine).
How do I get the data to be stored in the remote SQL server?
>
>
------------------------
>


Cowboy (Gregory A. Beamer) wrote:

Quote:

Originally Posted by

Check both databases and make sure it is not pointiong locally. As long as
machine name is correct, you should be on the other server.
>
NOTE: SQL Server 2005 requires SQL Browser on to connect remotely. You also
have to have proper transports set up, as some versions install without
TCP/IP or named pipes on.
>
--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com
>
*************************************************
Think outside of the box!
*************************************************
<brian.newman@.wpafb.af.milwrote in message
news:1161862621.467371.69570@.i3g2000cwc.googlegrou ps.com...

Quote:

Originally Posted by

I've got an app which provides data based on the user who is logged in.
So, I need the user data to be on the same db server as the other
data. I'm trying to do this using the membership API. I've set up the
tables and sprocs and so forth using the aspnet_regsql.exe (though, for
some reason, I had to do it using windows authentication rather than
using a SQL server account). I've modified the web.config file as
follows

<?xml version="1.0" encoding="utf-8"?>

<configuration
xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">

<connectionStrings>

<add name="SLAR-con" connectionString="Data
Source=mySQLserver;Initial Catalog=SLAR;User
Id=mydomain\myuserid;Password=mypassword" />

</connectionStrings>

<system.web>

<roleManager enabled="true" />

<authentication mode="Forms" />

<membership>

<providers>

<add connectionStringName="SLAR-con"
applicationName="SLAR" minRequiredPasswordLength="5"

minRequiredNonalphanumericCharacters="0"
name="CustomizedProvider"

type="System.Web.Security.SqlMembershipProvider" />

</providers>

</membership>

</system.web>

</configuration>

and I've tested the login and it seems to be working. However, when I
go into the database on the SQL server to look at the user I created,
the user authentication tables are all empty. The data isn't being
stored on the SQL server where I want it to be (I'm assuming it is
being stored in a SQL Server express database on the local machine).
How do I get the data to be stored in the remote SQL server?

------------------------


It is being stored locally (local to the machine on which I'm doing the
development), but I'm unclear on how to point it to the SQL server db.
I thought the edits shown in the top post I made to the web.config file
would handle that, but they don't. The SQL server db is SQL Server
2000.
By the way, thanks for the assist. I posted on Microsoft asp.net forum
and got 20 views, but no assist and got nothing from 4guysfromrolla.

Monday, March 26, 2012

Trouble Displaying Image in a User Control....

I am trying to add an image to my detail page without any success. I have a category page which displays items. You can choose an item which than going to the detail.aspx page displaying more information about the item. In the detail.aspx page the Page_Load event retrieves the ad number and puts it in a variable so I can retrieve that ad from the database. The Testad.ascx page is the user control with the logic I used for the detail.aspx page.

When I run this locally without trying to display an image it runs fine. The problem is displaying the image in the detail.aspx page. Below I entered what I thought would work. Can anyone take a good hard look at this and help get me on the right track.

At the very bottom I'm using the following to pull the image:

<IMG SRC='images/<%# Container.DataItem("ImageLabel") %>' Border="0"
Any opinions would be greatly appreciated.

Thank You.

I have included before detail.aspx and testad.ascx below.

===================================================
DETAIL.aspx PAGE...

<%@dotnet.itags.org. Register TagPrefix="ASPFD" TagName="Header" src="http://pics.10026.com/?src=header.ascx" %>
<%@dotnet.itags.org. Register TagPrefix="ASPFD" TagName="TestAd" src="http://pics.10026.com/?src=Testad.ascx" %>
<HTML>
<script runat="server">
Sub Page_Load(Sender As Object, E As EventArgs)
If Not IsPostBack Then
Dim AdNumSent As Integer

If Trim(Request.QueryString("AdNum")) = "" Then
Response.Redirect("default.aspx")
End If

Header.AddPageName("Ad Detail")

AdNumSent = Trim(Request.QueryString("AdNum"))
TestAd.GetAd(AdNumSent)

End If
End Sub
</script>
<body vlink="red">
<form runat="server">
<aspfd:header id="Header" runat="server" />
<aspfd:testad id="testAd" runat="server" />
</form>
</body>
</HTML
===================================================

TESTAD.ascx Page...

<%@dotnet.itags.org. Import Namespace="System.Data" %>
<%@dotnet.itags.org. Import Namespace="System.Data.OleDb" %>
<script runat="server">
Dim ConnectString, SelectStatement As String
Dim Connect As OleDbConnection = New OleDbConnection
Dim Adapter As OleDbDataAdapter = New OleDbDataAdapter
Dim TestCB As OleDbCommandBuilder
Dim TestDS As DataSet = New DataSet
Dim Row As DataRow

Public AdNum As Integer
Public Title As String
Public Description As String
Public Category As String
Public Price As String
Public Phone As String
Public Email As String
Public State As String
Public Posted As Date
Public Password As String
Public Image As String

Public HasErrors As Boolean
Public RowError As String

Sub GetAd(AdNumSent As Integer)
SelectStatement = "Select * From Ads Where AdNum=" & AdNumSent
ConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.mappath("Testdb.mdb") & ";"
Connect.ConnectionString = ConnectString
Adapter.SelectCommand = new OleDbCommand(SelectStatement, Connect)
Adapter.Fill(TestDS,"Ads")
TestCB = New OleDbCommandBuilder(Adapter)

If TestDS.Tables("Ads").Rows.Count > 0 Then
Row = TestDS.Tables("Ads").Rows(0)

AdNum = Row.Item("AdNum")
Title = Row.Item("Title")
Description = Row.Item("Description")
Category = Row.Item("Category")
Price = Row.Item("Price")
Phone = Row.Item("Phone")
Email = Row.Item("Email")
State = Row.Item("State")
Posted = Row.Item("Posted")
Password = Row.Item("Password")
Image = Row.Item("Image")

TitleLabel.Text = Title
DescriptionLabel.Text = Description
PriceLabel.Text = Price
PhoneLabel.Text = Phone
EmailLink.Text = Email
EmailLink.NavigateURL = "mailto:" & Email
StateLabel.Text = State
PostedLabel.Text = Posted
ImageLabel.Text = Image
End If

PostErrors
End Sub

Sub PlaceAd
Row = TestDS.Tables("Ads").NewRow

CopyToDS
Row.Item("Posted") = CDate(Today)
TestDS.Tables("Ads").Rows.Add(Row)
Adapter.Update(TestDS, "Ads")
PostErrors
End Sub

Sub EditAd
CopyToDS
Adapter.Update(TestDS, "Ads")
PostErrors
End Sub

Sub DeleteAd
TestDS.Tables("Ads").Rows(0).Delete
Adapter.Update(TestDS, "Ads")
PostErrors
End Sub

' Copy the values in the properties of this
' control in the TestDS
Private Sub CopyToDS
Row.Item("Title") = Title
Row.Item("Description") = Description
Row.Item("Category") = Category
Row.Item("Price") = CSng(Price)
Row.Item("Phone") = Phone
Row.Item("Email") = Email
Row.Item("State") = State
Row.Item("Password") = Password
Row.Item("Image") = Image
End Sub

Private Sub PostErrors
HasErrors = TestDS.HasErrors
If HasErrors Then
RowError = TestDS.Tables("Ads").Rows(0).RowError
End If
End Sub
</script>
<asp:datalist id="DataList1" runat="server"></asp:datalist>
<TABLE id="Table1" cellSpacing="0" cellPadding="2" width="100%" bgColor="lime" border="1">
<tr>
<td bgColor="yellow" colSpan="2"><asp:label id="TitleLabel" runat="server" font-bold="true" font-size="12 pt"></asp:label></td>
</tr>
<tr>
<td vAlign="top" width="25%">Description:</td>
<td><asp:label id="DescriptionLabel" runat="server" font-bold="true" font-size="12 pt"></asp:label></td>
</tr>
<tr>
<td width="25%">Price:</td>
<td>$<asp:label id="PriceLabel" runat="server" font-bold="true" font-size="12 pt"></asp:label>
</td>
</tr>
<tr>
<td width="25%">Phone:</td>
<td><asp:label id="PhoneLabel" runat="server" font-bold="true" font-size="12 pt"></asp:label></td>
</tr>
<tr>
<td width="25%">Email:</td>
<td><asp:hyperlink id="EmailLink" runat="server" font-bold="true" font-size="12 pt"></asp:hyperlink></td>
</tr>
<tr>
<td width="25%">Location:</td>
<td><asp:label id="StateLabel" runat="server" font-bold="true" font-size="12 pt"></asp:label></td>
</tr>
<tr>
<td width="25%">Posted Date:</td>
<td><asp:label id="PostedLabel" runat="server" font-bold="true" font-size="12 pt"></asp:label></td>
</tr>
<tr>
<td width="25%">Image:</td>
<td><IMG SRC='images/<%# Container.DataItem("ImageLabel") %>' Border="0"></td>
</tr>
</TABLE>Anyone have any idea??????
You forgot to DataBind()
Bleroy,

If I run the code without trying to pull an image it works and I didn't Data Bind() it. When an image is add into the mix do you have to Data Bind()? Is an image handled different?

Thanks.
A help would be apprieciated. This is really frustrating me. grrrr
What does ImageLabel contain? What do you see when you look at the client-side HTML?

Trouble firing events in code behind of user control

Ahoy

I am trying to use an asp:linkbutton on a .ascx file (user control), but it does not seem to be firing the click event in the code behind. I have put breakpoints on the first line of the event and in the page load of the user control, but it does not get to any of these. All it does is it postbacks to the server and goes through the page load event of the actual form (.aspx) that the user control is sitting on.

Any ideas?

ThanksAhoy

I am trying to use an asp:linkbutton on a .ascx file (user control), but it does not seem to be firing the click event in the code behind. I have put breakpoints on the first line of the event and in the page load of the user control, but it does not get to any of these. All it does is it postbacks to the server and goes through the page load event of the actual form (.aspx) that the user control is sitting on.

Any ideas?

Thanks

How are you assigning the Click Event to teh LinkButton and how are you handling it?
The following code is placed on the .ascx for the linkbutton's click event

Private Sub lnkLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lnkLogin.Click

'code

End sub

...it just never goes thru this code
Hmm that should not happen. Are you sure you are running on "Debug" mode and ASP.Net "Debugging" is enabled?
Make sure you are reloading your controls onto the form after the postback, or else the events for them wont fire. Happened to me :wave:
Yeh that was my problem - wasnt reloading the user controls on postback.

thanks patch :thumb:

trouble installing debugger

I am new ASP.net user and having been trying to get the debugger installed.
Are there any differences between running remotely and local machine?

Error Message received:
Error while running the project, unable to start debugging on the web server. The debugger is not properly installed. Run setup to install or repair the debugger.
thanks,
LauraAre you using visual studio.net?
If so, start the project temporarily by hitting ctrl + F5, this will start it without debugging. it may be because the site path is incorrect in IIS.
If you need help with this let me know...

Trouble Loading Code Behind Type

Hello,

I'm a new VS.NET user having the following issue.

I've created a new ASP.NET WEb Forms app and have been doing some basic
things with no real problems.

I have decided that the next thing in the development will be a secured area
of the app.

I have determined the Forms Authentication is the way I am going.

I have created a basic login form and modified the Web.config file in my
app's main virtual directory (where all of my files have hitherto resided).
I got this all working, no problem. When a page was requested, the user was
redirected to the login form as expected and when authenticated the
originally requested page was properly display.

Here is where the problem comes up. The site will be a mix of public and
"auth-required" pages. So this basically means that I do not want the
"main" virtual directory of the app secured.

Here is what I did.

First, I disabled the authentication requirement on the main virtual
directory.

Then I created a new virtual directory (under the main app's virtual
directory) and called it "Secure".

I moved the Login.aspx (my custom login form) into the Secure virutal
directory and created an additional blank page in there as well.

I put a new copy of Web.config in the Secure virtual directory and
configured it up for Forms based authentication.

Here is what I expect to happen.

When a page in the app's main virtual directory is requested it loads
for anyone (this works fine).

When a page is initially requested in the Secure virtual directory the
user should be redirected to the Login form (the redirection occurs as
expected)

Here is the problem: The Login.aspx page pops a run time error
complaining that the code behind type cannot be loaded.
Parser Error Message: Could not load type 'RPG.Login'.
The application is named "RPG"
Here is the @dotnet.itags.org.Page
<%@dotnet.itags.org. Page Language="vb" AutoEventWireup="false"
Codebehind="Login.aspx.vb" Inherits="RPG.Login"%
Note: This was not erroring out when page in question was in the app's main
virtual directory. It only occurs for pages (I have tested a "Hello World"
page in the same virtual directory with the same error.

This seems to be some sort of pathing issue, but with the .aspx file and the
.aspx.vb file in the same folder, I don't get the problem. I've tried
changing the reference in the "Inherits" attribute to things like
RPG.Secure.Login but I'm too new to the environment to understand the
Namespace.Class reference and how it is effected by the location of the
files in question.

TIADo you have a file called "RPG.dll" in the /bin folder in the web application root?
Yes. RPG/bin/RPG.dll exists.

Saturday, March 24, 2012

Trouble saving html in a string variable

I'm trying to allow a user to enter html text into a textBox (FreeTextBox) but am getting an error upon submitting:

A potentially dangerous Request.Form value was detected from the client (noteTextBox="<H2><FONT size=6>asd...").
Description:Request Validation has detected a potentially dangerous client input value, and processing of the request has been aborted. This value may indicate an attempt to compromise the security of your application, such as a cross-site scripting attack. You can disable request validation by setting validateRequest=false in the Page directive or in the configuration section. However, it is strongly recommended that your application explicitly check all inputs in this case.

Exception Details:System.Web.HttpRequestValidationException: A potentially dangerous Request.Form value was detected from the client (noteTextBox="<H2><FONT size=6>asd...").

Anybody know how to deal with this while still allowing me to save the html?

<%@. Page...... ValidateRequest="false".....%>


I think the reason for this error was that someone could enter a <script> tag in your textbox with javascript code, and then if you grab that value from the form and display directly it on another page, the code in the <script> tag would be executed on your user's computer... this could be potentially bad. i usually turn the error off though, like the previous poster. If you HtmlEncode() anything that you display that ultimately came from the user, it should be ok to turn it off.


How do I HtmlEncode() this text?


dim myText as String = Server.HtmlEncode(yourTextbox.Text)

Trouble with authentication in asp.net

Im trying to setup windoes based security for my asp.net web app in server 2003. This is what I have done

* Created the user "testuser" on the local machine

* created the group "testgroup" on the local machine

* added testuser -> testgroup

* created an asp.net webapp in IIS and set it to windows authentication

* in explorer, I have added testgroup to read rights on the web app folder.

* Now I run the app, I enter the username and password and it let me in..

BUT when I write User.IsInRole("testgroup") I get "false"... why is that? I should get "true"...

so my problem is with the groups, everything else works fine!!!

whats the problem?
/HenrikHave you set identity impersonation to true?
Yes!! But im not sure it matters?

I have done something similar for a winforms app, but there I fetched the group info from the AD using system.directoryservices and then created genericprincipal and genericidentity... then it works to check Thread.User.IsInRole("wewwq"),,,

im not sure what to do with asp.net to get the same functionality...
/henrik
Maybe you need to disable "anonymous" in the IIS server.
It may be passing "anonymous" instead of the user id.
?
i have disabled anonymous login in the IIS, and set to windows authentication... and I get the correct username when using User.Identity.Name its the groups that dont work correct

/Henrik
Have you restarted the machine for the group changes to take effect? Or tried issuing iisreset at the command prompt?

Trouble with databinding

Hi,

I'm trying to add databinding to the wizard control. Basically a user is
entering their email address and I want to validate this to a sql database
when the hit next but I cannot get this to work.

Any idea how I would go about doing this?

Thanks in advance

--

- Hayden KirkWhat you need to do is handle the NextButtonClick and
PreviousButtonClick events. In those events you can check the value
for the ActiveStepIndex which will coorespond with each of your steps.
If the right step is the current one you can run your check against the
database. If you want to cancel the step you can set the Cancel
property on the event to true.

Here is a code snippet.

protected void Wizard1_NextButtonClick(object sender,
System.Web.UI.WebControls.WizardNavigationEventArg s e)
{
bool isEmailValid = FindEmail(txtEmail.Text);
e.Cancel = ! isEmailValid();
}

You may also want to attach a custom validator to the email textbox and
then you can simply ask the validator if it is valid. It will then
automatically display the error indicator, like a red star next to the
textbox.

Brennan Stehling
http://brennan.offwhite.net/blog/
Hayden Kirk wrote:

Quote:

Originally Posted by

Hi,
>
I'm trying to add databinding to the wizard control. Basically a user is
entering their email address and I want to validate this to a sql database
when the hit next but I cannot get this to work.
>
Any idea how I would go about doing this?
>
Thanks in advance
>
--
>
- Hayden Kirk


Thanks for responding Brennan.

This is working perfectly. I was wondering though, what is the best way to
go about getting the data from the mssql database. I only need to check to
see if their email address already exists or not, possibly delete it if they
wish to unsubscribe. Can I use the sqldatasource control for this? Or is is
better to code this by hand?

I was wondering if someone could give me a quick example of doing it by
hand.

Thanks,

"Brennan Stehling" <offwhite@.gmail.comwrote in message
news:1157942127.738960.146550@.e3g2000cwe.googlegro ups.com...

Quote:

Originally Posted by

What you need to do is handle the NextButtonClick and
PreviousButtonClick events. In those events you can check the value
for the ActiveStepIndex which will coorespond with each of your steps.
If the right step is the current one you can run your check against the
database. If you want to cancel the step you can set the Cancel
property on the event to true.
>
Here is a code snippet.
>
protected void Wizard1_NextButtonClick(object sender,
System.Web.UI.WebControls.WizardNavigationEventArg s e)
{
bool isEmailValid = FindEmail(txtEmail.Text);
e.Cancel = ! isEmailValid();
}
>
You may also want to attach a custom validator to the email textbox and
then you can simply ask the validator if it is valid. It will then
automatically display the error indicator, like a red star next to the
textbox.
>
Brennan Stehling
http://brennan.offwhite.net/blog/
>
Hayden Kirk wrote:

Quote:

Originally Posted by

>Hi,
>>
>I'm trying to add databinding to the wizard control. Basically a user is
>entering their email address and I want to validate this to a sql
>database
>when the hit next but I cannot get this to work.
>>
>Any idea how I would go about doing this?
>>
>Thanks in advance
>>
>--
>>
>- Hayden Kirk


>


Here is a snippet for a basic query with ADO.NET.

using System;
using System.Data;
using System.Data.SqlClient;

class Sample
{
public static void Main()
{
SqlConnection nwindConn = new SqlConnection("Data
Source=localhost;Integrated Security=SSPI;Initial Catalog=northwind");

SqlCommand catCMD = nwindConn.CreateCommand();
catCMD.CommandText = "SELECT CategoryID, CategoryName FROM
Categories";

nwindConn.Open();

SqlDataReader myReader = catCMD.ExecuteReader();

while (myReader.Read())
{
Console.WriteLine("\t{0}\t{1}", myReader.GetInt32(0),
myReader.GetString(1));
}

myReader.Close();
nwindConn.Close();
}
}

Hayden Kirk wrote:

Quote:

Originally Posted by

Thanks for responding Brennan.
>
This is working perfectly. I was wondering though, what is the best way to
go about getting the data from the mssql database. I only need to check to
see if their email address already exists or not, possibly delete it if they
wish to unsubscribe. Can I use the sqldatasource control for this? Or is is
better to code this by hand?
>
I was wondering if someone could give me a quick example of doing it by
hand.
>
Thanks,
>
"Brennan Stehling" <offwhite@.gmail.comwrote in message
news:1157942127.738960.146550@.e3g2000cwe.googlegro ups.com...

Quote:

Originally Posted by

What you need to do is handle the NextButtonClick and
PreviousButtonClick events. In those events you can check the value
for the ActiveStepIndex which will coorespond with each of your steps.
If the right step is the current one you can run your check against the
database. If you want to cancel the step you can set the Cancel
property on the event to true.

Here is a code snippet.

protected void Wizard1_NextButtonClick(object sender,
System.Web.UI.WebControls.WizardNavigationEventArg s e)
{
bool isEmailValid = FindEmail(txtEmail.Text);
e.Cancel = ! isEmailValid();
}

You may also want to attach a custom validator to the email textbox and
then you can simply ask the validator if it is valid. It will then
automatically display the error indicator, like a red star next to the
textbox.

Brennan Stehling
http://brennan.offwhite.net/blog/
Hayden Kirk wrote:

Quote:

Originally Posted by

Hi,
>
I'm trying to add databinding to the wizard control. Basically a user is
entering their email address and I want to validate this to a sql
database
when the hit next but I cannot get this to work.
>
Any idea how I would go about doing this?
>
Thanks in advance
>
--
>
- Hayden Kirk


Thursday, March 22, 2012

Trouble with Radiobuttons

Hi,

I am working on this project of creating webforms and this one particular page has a bunch of radiobuttons in it. Once the user clicks one of the radiobuttons and then clicks on submit, the user is redirected to a different webform. In the event handler for the submit button, I check to see if that one particular radiobutton has been clicked or not ,kinda like this below:

privatevoid InitializeComponent()

{

this.submit_button.Click +=new System.EventHandler(this.submit_button_Click);

}

privatevoid submit_button_Click(object sender, System.EventArgs e)

{

if (radiobutton1.Checked ==true)

{

Response.Redirect("page1.aspx");

}

The problem is when I check radiobutton1 and then click submit, nothing happens and I stay on the same page. I ran the debugger and it didn't even step through the code. Can anyone help me out here?

Try this - uses both types of radio button/list

<%@.PageLanguage="C#" %>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<scriptrunat="server">

protectedvoid RadioButton3_CheckedChanged(object sender,EventArgs e)

{

Response.Redirect("Default.aspx?Fruit=" + Server.HtmlEncode(((RadioButton)sender).Text));

}

protectedvoid RadioButtonList1_SelectedIndexChanged(object sender,EventArgs e)

{

Response.Redirect("Default.aspx?Fruit=" + Server.HtmlEncode(RadioButtonList1.SelectedValue));

}

</script>

<htmlxmlns="http://www.w3.org/1999/xhtml">

<headrunat="server">

<title>Untitled Page</title>

</head>

<body>

<formid="form1"runat="server">

<div>

<asp:RadioButtonID="RadioButton1"runat="server"GroupName="RB1"Text="Apples"OnCheckedChanged="RadioButton3_CheckedChanged"/>

<asp:RadioButtonID="RadioButton2"runat="server"GroupName="RB1"Text="Oranges"

OnCheckedChanged="RadioButton3_CheckedChanged"/>

<asp:RadioButtonID="RadioButton3"runat="server"GroupName="RB1"Text="Gone Bananas"

OnCheckedChanged="RadioButton3_CheckedChanged"/>

</div>

<div>

<asp:RadioButtonListID="RadioButtonList1"runat="server"OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged">

<asp:ListItem>Pears</asp:ListItem>

<asp:ListItem>Cherries</asp:ListItem>

<asp:ListItem>WinkleBerry</asp:ListItem>

</asp:RadioButtonList>

</div>

<asp:LinkButtonID="LinkButton1"runat="server">Submit</asp:LinkButton>

</form>

</body>

</html>


Thanks for the response...I am working with .aspx files...So instead of embedding scripts like you suggested, I have to write backend code in the .aspx.cs files..Its just that after I click on the submit button it should hit that part of the code where I have the event handler in case the submit button is clicked. I still can't figure out why its not doing that...I am working on a visual studio 2003 platform

Tuesday, March 13, 2012

Trouble With UrlReferrer

I'm trying to store a session variable to store the filename of the page where the user was before the current one.

The reasoning is that I'm trying to store the value so that if a users session times out, I have the redirected to the logon page. Once they've logged back in I'd like to automatically take them back to the page where they were before.

I've tried using Session("ref")=Request.UrlReferrer to store the value. To test that I have the referring page I've created a label and assigned it the value of Session("Ref") by using lblReferrer.Text=Session("ref").

At first I was just getting a nothing where I exprected to see the referrer on the page. Today it's throwing an error saying can't convert a Uri to a String.

I've had a look at the documentation for Uri's but can't see a way to get just the referrers url.

Im I going about this the wrong way, or is it something basic I've missed?

Thanks
JasonSession("ref")=Request.UrlReferrer.ToString()
I did have .ToString() in the code at some stage, but I obviously in the wrong place.

In any case, you've solved my problem. Thanks for your help.
Jason