Cannot convert type ‘ASP.login_aspx’ to ‘System.Web.UI.WebControl’

If you have used a Page that effectively uses a codebehind classname
that is the same as say the Login control, that is Login, e.g. your
page was called Login.aspx, then when you pre-compile (publish) the web
site as an updateable web site, the aspx is retained and tries to
compile against a type called Login in the code behind. It does not
resolve to be that in the codebehind assembly

Try using a classname for your codebehind and defined in the inherits
that does not clash with a type in System.Web, e.g. LoginPage, or
qualify the class and therefore the inherits statement with a
namespace, e.g.
in the .aspx file:

<%@ page … inherits=”MyNameSpace.Login” %.
in the code behind file:

namespace MyNameSpace

{ public partial class Login : System.Web.UI.Page

{

..

}

}

how to get aspx page username ?

in vb its system.environment.username – whats the equivalent in aspx with
code behind (VB) ?

——————————————————————————–

In the codebehind of your aspx code, you could use:

Page.User.Identity.Name ;

In a custom class, you could use:
HttpContext.Current.User.Identity.Name;

——————————————————————————–

thanks but niether seems to work – aspx accepts it but it does nothing!

——————————————————————————–

It depends how you would like to use it.

If you want to get the Windows username you have to make sure you disabled
anonymous access in IIS.

If you use forms authentication you can make a custom principal:
System.Security.Principal.GenericIdentity identity = new
System.Security.Principal.GenericIdentity(“testUse rName”);
System.Security.Principal.GenericPrincipal principal = new
System.Security.Principal.GenericPrincipal(identit y,new string[]{
“TestRole”});

Context.User = principal;

Validation of ViewState Mac failed in ASP.NET 2

I met this asp.net Exception when I create a .mobi application followed the new policy of .mobi (I think it is WAP 2.0). I searched Google and got the following article, then I copy to here ((from : http://aspadvice.com/blogs/joteke/archive/2006/02/02/15011.aspx)). Later I will try to use the solution for my application

If you get this Exception

[HttpException (0x80004005): Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.]

and

* you know *for sure* that you aren’t using a web farm
* it seems that it appears when using built-in databound controls such as GridView, DetailsView or FormView which utilize DataKeyNames.
* it appears if you have a large page which loads slowly for any reason

Paypal STANDARD Website Payment Walkthrough?

Paypal STANDARD Website Payment Walkthrough?

Here is from a question about Commerce Starter Kit (asp.net). maybe it is can used for any e-commerce website code to setup Paypal payment.

Paypal STANDARD Website Payment Walkthrough?

To setup a fictitious Paypal account in the Sandbox and confirming the account:

1. Log into the Developer Central website at http://developer.paypal.com.
2. This will bring you to the Developer Central homepage.
3. Click on the Sandbox link found on the right side of the page or the tab found at the top.
4. This will list your fictious sandbox accounts.  To create a new one, click on Create Account.
5. When you click Create Account, it will open a new page of the Register a New Paypal account on the Sandbox environment.
6. You may select one of three account types (casual shoppers, casual sellers, or business owners)
7. For this example, let’s select casual shopper by clicking on the Start Now button
8. Enter in the pertinent information on the Create A Paypal account page and click on the “I Agree, Create My Account”.
9. This will take you to the Account Sign Up results page.
10. It now tells you to confirm your email address… Go back to the Developer Central page where the Sandbox tab is.  Make sure to click the tab again to refresh the list of test accounts with the new account showing up on the list!
11. Now… click on the Email tab found just two tabs to the right of the sandbox tab – this is where you will find all the email coming to the new fictitious email box.  You will see an email there with the subject Activate Your Paypal account.  Click the link of the “email”.
12. A fake email should popup on a new browser window – copy the confirmation number to the “clipboard”
13. Go back to the Sandbox tab, and select the new test account and click the Launch Sandbox button. Sign in to the sandbox with the new test account email address and password by clicking the Login button.
14. To the left you will see a link to “Confirm Email” – click it.
15. Then click the link… “Click here if a link DOES NOT appear in the email”
16. Paste the confirmation number (saved in the clipboard) into the field and click the Confirm button.
17. The account is NOW confirmed.  You may now click on Continue or Skip to do more setup for the account.

Hope this helps.

A button style HyperLink in ASP.NET

<asp:HyperLink ID=”linkCountry” runat=”server”
NavigateUrl='<%# “CountryLst.aspx?ContinentID=” + DataBinder.Eval(Container.DataItem,”continentid”) %>’
Text='<%# DataBinder.Eval(Container.DataItem, “continentname”) %>’
Font-Bold=”True” ForeColor=”Black” Font-Size=”Medium” BorderWidth=”3px” BackColor=”LightGray” BorderStyle=”Outset” Width=”83px” style=”TEXT-DECORATION: none”  >

Generating Client-Side Script for Postback

(from: http://msdn2.microsoft.com/en-us/library/aa720099(VS.71).aspx)

Only two HTML form elements (button and image button) cause form postback. If your custom control renders an HTML element that does not cause postback (such as a text box or a link button) and you want the control to initiate postback, you can program this in ASP.NET through an event architecture that relies on client-side script (JScript, JavaScript).

Control developers need to make a few small changes to their controls to enable this postback mechanism. The following code fragment shows (in bold) the code that must be added to the Render method of a control to initiate postback.

[C#]
protected override void Render(HtmlTextWriter output) {
                  output.Write("<a  id=\"" + this.UniqueID + "\" href=\"javascript:" + Page.GetPostBackEventReference(this) +"\">");
                  output.Write(" " + this.UniqueID + "</a>");
            }
[Visual Basic]
Protected Overrides Sub Render(output As HtmlTextWriter)
   output.Write("<a  id=""" & Me.UniqueID & _
         """ href=""javascript:" & _
         Page.GetPostBackEventReference(Me) & """>")
   output.Write(" " & Me.UniqueID & "</a>")
End Sub

The GetPostBackEventReference method emits client-side script that initiates postback and also provides a reference to the control that initiated the postback event.

To understand what the GetPostBackEventReference method does, compile the code in the next section, Postback Using Client-Side Script Sample, and request the accompanying .aspx page in your browser. If you view the source for the rendered page using your browser’s View Source command, you will see the following HTML and script. (The actual values of the name and the ID attributes of the form will differ, and so will the value attribute of the hidden variable.)

<html>
<body>
<form name="ctrl2" method="POST" action="MyLinkButton.aspx" id="ctrl2">
<input type="hidden" name="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" value="dDwtMjI1NTgwNDE2Ozs+eIZ+AfRvoCj1nWimbh+zPv/rKNg=" />                  
Here is the custom link button.<br>
<a  id ="Link" href="javascript:__doPostBack('Link','')"> Link</a> 
<br><br>
<input name="TextBox" type="text" value="Click the link" id="TextBox" style="background-color:Cyan;width:200px;" /> 
<br>                                                
<script language="javascript">
<!--
      function __doPostBack(eventTarget, eventArgument) {
            var theform = document.ctrl2
            theform.__EVENTTARGET.value = eventTarget
            theform.__EVENTARGUMENT.value = eventArgument
            theform.submit()
      }
// -->
</script>
</form>                  
</body>                        
</html>

The elements in bold in this example — two hidden fields and the client-side script method — are added by the ASP.NET page framework. The hidden form fields indicate which server control to post to and optionally specify an argument to pass. The client-side script method is used to set the hidden fields and causes the form to be submitted to the server. For a complete sample, see Postback Using Client-Side Script Sample.

See Also

Postback Using Client-Side Script Sample

Get relavated value of selected row of GridView using javascipts

(from: http://geekswithblogs.net/azamsharp/archive/2006/08/29/89697.aspx)
So, here is the story. I have a GridView which contains the ASP.NET CheckBox control. Each row also have the primary key of the database table. Now, I need to get the ID of the selected checkbox using JavaScript. I used a hidden field to store the ID of the row (The row is hidden and the user cannot see it on the display but you can see the value if you do the view source). Now, I like to access the hidden field of the selected row of the GridView.

<asp:TemplateField>

<ItemTemplate>

<asp:CheckBox id=”chkSelect” runat=”server” />

<asp:HiddenField ID=”hfID” runat=”server” Value='<%# Eval(“ID”) %>’ />

</ItemTemplate>

</asp:TemplateField>

And here is the JavaScript code:

function GetIDFromHiddenField()

{

var elements = document.getElementsByTagName(“INPUT”);

var ID;

var count = 0;

for(i=0; i< elements.length; i++)

{

if(elements[i].type == ‘checkbox’)

{

if(elements[i].checked == true)

{

count = count + 1;

ID= elements[i].nextSibling.nextSibling.value;

}

}

}

// check if more then one exam is selected. If so, then alert the user

if(count > 1) { alert(‘Please only select a single item from the list’); return (-1); }

else return ID;

}

Althought I am only allowing the user to select a single item I am sure you got the basic idea.

Show all GridView Rows in EditMod

(from: http://aspadvice.com/blogs/azamsharp/archive/2006/11/08/Show-all-GridView-Rows-in-EditMode.aspx)

Sometimes, in the application we have a requirement that you need to show the GridView rows in edit mode. This means that all the rows will contain textboxes and the data should be present in the textboxes. Once, you are done with editing you can update and get back to the view mode. In this post I will simply show you how to change the mode of the GridView from view to edit. I will not be using any datasource controls.

The first task is the create a GridView. Check out the html code to create the GridView control:

<asp:GridView ID=”gvUsers” AutoGenerateColumns=”false” runat=”server” OnRowDataBound=”gvUsers_RowDataBound”>

<Columns>

<asp:TemplateField HeaderText=”User ID”>

<ItemTemplate>

<asp:Label ID=”lblUserID” runat=”server” Text=’<%# Eval(“UserID”) %> />

</ItemTemplate>

</asp:TemplateField>

<asp:TemplateField HeaderText=”First Name”>

<ItemTemplate>

<asp:Label ID=”lblFirstName” Visible=’<%# !(bool) IsInEditMode %> runat=”server” Text=’<%# Eval(“FirstName”) %> />

<asp:TextBox ID=”txtFirstName” Visible=’<%# IsInEditMode %> runat=”server” Text=’<%# Eval(“FirstName”) %> />

</ItemTemplate>

</asp:TemplateField>

<asp:TemplateField HeaderText=”Last Name”>

<ItemTemplate>

<asp:Label ID=”lblLastName” Visible=’<%# !(bool) IsInEditMode %> runat=”server” Text=’<%# Eval(“LastName”) %> />

<asp:TextBox ID=”txtLastName” Visible=’<%# IsInEditMode %> runat=”server” Text=’<%# Eval(“LastName”) %> />

</ItemTemplate>

</asp:TemplateField>

</Columns>

</asp:GridView>

Check out the screen shot below:

GridViewAllRowsEditMode1

As, you can see in the html code that both my label and the textbox are in the ItemTemplate and there visibility depends on the IsInEditMode property. Now, let’s check out the code behind:

private bool isEditMode = false;

protected void Page_Load(object sender, EventArgs e)

{

if (!Page.IsPostBack)

{

BindData();

}

}

private void BindData()

{

string connectionString = “Server=localhost;Database=School;Trusted_Connection=true”;

SqlConnection myConnection = new SqlConnection(connectionString);

SqlDataAdapter ad = new SqlDataAdapter(“SELECT UserID, FirstName, LastName FROM Users”, myConnection);

DataSet ds = new DataSet();

ad.Fill(ds);

gvUsers.DataSource = ds;

gvUsers.DataBind();

}

// This method will put the GridView in the edit mode

protected void Button1_Click(object sender, EventArgs e)

{

isEditMode = true;

BindData();

}

protected bool IsInEditMode

{

get { return this.isEditMode; }

set { this.isEditMode = value; }

}

protected void Button2_Click(object sender, EventArgs e)

{

isEditMode = false;

BindData();

}

When the button is clicked I simply change the isEditMode to true or depending depending that if I want to view the GridView in edit mode or view mode. Check out the effect below:

SQL : ntext, text,image field

Transact-SQL Reference
ntext, text, and image

Fixed and variable-length data types for storing large non-Unicode and Unicode character and binary data. Unicode data uses the UNICODE UCS-2 character set.

ntext

Variable-length Unicode data with a maximum length of 230 – 1 (1,073,741,823) characters. Storage size, in bytes, is two times the number of characters entered. The SQL-92 synonym for ntext is national text.

text

Variable-length non-Unicode data in the code page of the server and with a maximum length of 231-1 (2,147,483,647) characters. When the server code page uses double-byte characters, the storage is still 2,147,483,647 bytes. Depending on the character string, the storage size may be less than 2,147,483,647 bytes.

image

Variable-length binary data from 0 through 231-1 (2,147,483,647) bytes.

Remarks

These functions and statements can be used with ntext, text, or image data.

Functions Statements
DATALENGTH READTEXT
PATINDEX SET TEXTSIZE
SUBSTRING UPDATETEXT
TEXTPTR WRITETEXT
TEXTVALID

Godaddy share hosting doesn’t support CSK 2 ?

CSK 2.0 , Commerce Starter Kit —

The PayPal-enabled Commerce Starter Kit is a free, open source e-commerce storefront written in C# specifically for ASP.NET 2.0. It features out-of-the-box product catalog and shopping cart functionality that allows web developers to setup, run, and maintain an online store with little or no costs, license fees, or limitations. Some assembly required.

http://pdn.paypal.com/commercestarterkit/default.htm

It is a good open source e-commercial package for those people want to open their online stores.

But, there is a very important problem: Does your hosing support CSK 2.0?

check here:  http://forums.commercestarterkit.org/

How To Push Your Site Live

If you need some help putting the CSK on your web host’s server, here’s a walkthrough. It’s important to note that the CSK only works in Full Trust. Most ISPs will only allow .NET 2.0 Web sites to run in Partial Trust (aka Medium Trust). This won’t allow the CSK to make Web Service calls to PayPal (or the gateway of your choice) so please make sure you ask your ISP if they will support full trust.

I heard Godaddy.com’s share hosting maybe don’t have something that CSK needs: GoDaddy locks down all sites under medium trust which does not allow the PayPal API to execute, thus disabling the site (http://forums.commercestarterkit.org/forums/1/207/ShowThread.aspx ), but you also see the information seems Godaddy and MS are doing sth. to resolve this problem.

Just now I have send my question about this to Godaddy’s support team. We just see what they will reply to me.

Result: Godaddy response their share hosting only medium trust just like most of ISP.

Finally, I found info that maybe CSK 2.0 can use Medium Trust hosting for Paypal standard edition not paypal pro, that means if you don’t set Paypal pro payment method just Paypal standard, it can work well.

http://forums.commercestarterkit.org/forums/thread/9010.aspx