Ramesh S 129 Posting Pro

Try this code.

.aspx code

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DemoPage32.aspx.cs" Inherits="DemoPage32" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        Quantity : &nbsp;&nbsp;&nbsp;
        <asp:TextBox ID="txtQuantity" runat="server"></asp:TextBox><br />
        Date  : &nbsp;&nbsp;&nbsp; 
        <asp:TextBox ID="txtDate" runat="server"></asp:TextBox>        
        <asp:CustomValidator ID="cvValidateDate" runat="server" ErrorMessage="Date must be entered"></asp:CustomValidator><br />
        <asp:Button ID="btnValidate" runat="server" Text="Validate" 
            onclick="btnValidate_Click" />
        
    </div>
    </form>
</body>
</html>

C# code

protected void btnValidate_Click(object sender, EventArgs e)
    {
        if (!String.IsNullOrEmpty(txtQuantity.Text))
        {
            int qty = int.Parse(txtQuantity.Text);
            if (qty > 0)
            {
                if (String.IsNullOrEmpty(txtDate.Text))
                {
                    cvValidateDate.ErrorMessage = "Date must be entered";
                    cvValidateDate.IsValid = false;
                }
            }
        }
    }
minbor commented: Thanks for your help. Thats exactly what I need +3
Ramesh S 129 Posting Pro
Ramesh S 129 Posting Pro

FormView is basically used to display the values of a single record from a data source.

The controls in the ItemTemplate will be rendered only after binding a data source to the FormView control.

In the BindFormView() method, you didn't bind any data source to the FormView control. Therefore myFormView.FindControl("myLabel") returns always nothing.

Try after data binding to the FormView. It will return the Label control.

Ramesh S 129 Posting Pro

By defult, SQL membership provider creates the database with name 'aspnetdb'. But you can use your own database to create tables related to membership provider.

Also the tables and stored procedures are prefixed with 'aspnet'. The views are prefixed with 'vw_aspnet'. Therefore chances are very remote to conflict with other tables related to your application.

Also if you want to implement authentication and role management without using membership provider, then you need to develop your own implementation which may need a lot of efforts.

Dhaneshnm commented: Nice explanation +1
Ramesh S 129 Posting Pro

Hi Anupama,

Try the following code.

.aspx code

<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="CustomValidator"></asp:CustomValidator>
        <asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound"
            OnRowCommand="GridView1_RowCommand">
            <Columns>

                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True" OnTextChanged="TextBox1_TextChanged"></asp:TextBox>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>

C# Code behind

public static bool IsValidDate(string date)
    {
        try
        {

            Regex reDate = new Regex(@"\b([0-9]{1,2}[\s]?[\-/\.\–][\s]?[0-9]{1,2}[\s]?[\-/\.\–][\s]?[0-9]{2,4})\b|\b(([0-9]{1,2}[TtHhSsRrDdNn]{0,2})[\s]?[\-/\.,\–]?[\s]?([Jj][Aa][Nn][Uu]?[Aa]?[Rr]?[Yy]?|[Ff][Ee][Bb][Rr]?[Uu]?[Aa]?[Rr]?[Yy]?|[Mm][Aa][Rr][Cc]?[Hh]?|[Aa][Pp][Rr][Ii]?[Ll]?|[Mm][Aa][Yy]|[Jj][Uu][Nn][Ee]?|[Jj][Uu][Ll][Yy]?|[Aa][Uu][Gg][Uu]?[Ss]?[Tt]?|[Ss][Ee][Pp][Tt]?[Ee]?[Mm]?[Bb]?[Ee]?[Rr]?|[Oo][Cc][Tt][Oo]?[Bb]?[Ee]?[Rr]?|[Nn][Oo][Vv][Ee]?[Mm]?[Bb]?[Ee]?[Rr]?|[Dd][Ee][Cc][Ee]?[Mm]?[Bb]?[Ee]?[Rr]?)[\s]?[\-/\.,\–]?[\s]?[']?([0-9]{2,4}))\b|\b(([Jj][Aa][Nn][Uu]?[Aa]?[Rr]?[Yy]?|[Ff][Ee][Bb][Rr]?[Uu]?[Aa]?[Rr]?[Yy]?|[Mm][Aa][Rr][Cc]?[Hh]?|[Aa][Pp][Rr][Ii]?[Ll]?|[Mm][Aa][Yy]|[Jj][Uu][Nn][Ee]?|[Jj][Uu][Ll][Yy]?|[Aa][Uu][Gg][Uu]?[Ss]?[Tt]?|[Ss][Ee][Pp][Tt]?[Ee]?[Mm]?[Bb]?[Ee]?[Rr]?|[Oo][Cc][Tt][Oo]?[Bb]?[Ee]?[Rr]?|[Nn][Oo][Vv][Ee]?[Mm]?[Bb]?[Ee]?[Rr]?|[Dd][Ee][Cc][Ee]?[Mm]?[Bb]?[Ee]?[Rr]?)[\s]?[,]?[\s]?[0-9]{1,2}[TtHhSsRrDdNn]{0,2}[\s]?[,]?[\s]?[']?[0-9]{2,4})\b");
            Match mDate = reDate.Match(date);
            if (!mDate.Success)
                return false;


            System.IFormatProvider ifpformat = new System.Globalization.CultureInfo("en-GB", true);
            DateTime tempDate = Convert.ToDateTime(date, ifpformat);
            if ((tempDate.Year > 1900) && (tempDate.Year < 2100))
                return true;
            else
                return false;

        }
        catch (System.FormatException)
        {
            return false;
        }
    }
    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {
        string strDate = (sender as TextBox).Text;
        if (!String.IsNullOrEmpty(strDate) && !IsValidDate(strDate))
        {
            CustomValidator1.ErrorMessage = "Invalid date";
            CustomValidator1.IsValid = false;
            return;
        }
    }

In future, post your ASP.NET related questions here.

Ramesh S 129 Posting Pro

If the variable 'imgfilepath' has a invalid path or file name, it will throw
System.IO.DirectoryNotFoundException with error message 'Could not find a part of the path .......'.

Otherwise post the complete exception message. It will help to identity the exact issue.

Ramesh S 129 Posting Pro

Hi Pankaj,

Mark this thread as solved if your question is answered.

Ramesh S 129 Posting Pro

Hi cavpollo,

Mark this thread as solved if your question is answered.

Ramesh S 129 Posting Pro

It can be done by setting default button property at page level.

The defaultbutton property can be specified at the Form level in the form tag

<form id="form1" runat="server" defaultbutton="button2 ">
Ramesh S 129 Posting Pro

You are asking about Nested Master Pages feature of ASP.NET.

Master pages can be nested, with one master page referencing another as its master.

Visit this link: Nested ASP.NET Master Pages. It explains about nested master pages in detail with sample code.

Also visit these links.
http://weblogs.asp.net/scottgu/archive/2007/07/09/vs-2008-nested-master-page-support.aspx
http://www.codeguru.com/csharp/csharp/cs_network/internetweb/article.php/c12621/
http://www.aspfree.com/c/a/ASP.NET/Creating-a-Nested-Master-Page/

Ramesh S 129 Posting Pro

Place your connection information in web.config. Assume that your database is in App_data folder of your of web site.

<connectionStrings>

<add name="TestConnectionString" connectionString="Server=.\SQLExpress;AttachDbFilename=|DataDirectory|student1.mdf;Integrated Security=True;User Instance=True"  providerName="System.Data.SqlClient"/>
    </connectionStrings>

To use the connection string from web.config

Using System.Data;
Using System.Data.SqlClient;
Using System.Configuration;
.
.
.

    SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["TestConnectionString"].ConnectionString);

    SqlDataAdapter adapter = new SqlDataAdapter();
    adapter.SelectCommand = new SqlCommand(
            "SELECT * FROM Customers", connection);
    DataSet dsCustomers = new DataSet();
    adapter.Fill(dsCustomers);
   connection.Close();
Ramesh S 129 Posting Pro

It means that the index '4' in the collection e.Row.Cells is outside the bounds of that collection. So it throws the error.

The first column starts with the index 0. Therefore you need to specify the index as 3 if you want to hide the 4th displayed column of the GridView.

Change your code as below

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header || e.Row.RowType == DataControlRowType.DataRow)        
        {            
            e.Row.Controls[3].Visible = false;            
        }
    }

Instead of handling RowDataBound, you can also hide a auto generated column after binding your GridView. See this code.

GridView1.DataSource = yourDataTable;
        GridView1.DataBind();
        GridView1.HeaderRow.Cells[3].Visible = false;
        foreach (GridViewRow gvr in GridView1.Rows)
        {
            gvr.Cells[3].Visible = false;
        }
Ramesh S 129 Posting Pro

I found a solution in a forum that installing Visual Studio 2008 SP1 addressed this issue.

Ramesh S 129 Posting Pro

Hi John,

Why do you want to construct the connection string dynamically in your class file?

Store the connection information in web.config file for web applications and app.config file for WinForms application. You can retrieve the conneciton information using System.Configuration.ConnectionStringSettings class in your class file.

For your question, You can use Server.MapPath in your class file using HttpContext object. Try System.Web.HttpContext.Current.Server.MapPath method.

Ramesh S 129 Posting Pro

CHECK constraint is not available in the CREATE TABLE statement for Access 2007 database.

Instead, you can define validation rule using Design View.

Ramesh S 129 Posting Pro

I have checked your code.

Actually it does not disable enter key in TextArea. It disable enter key only in Textbox field. But you didn't use any textboxes in your code.


I have changed your code to disable enter key in first text area(field1) only.

<html>
<head>
    <title>The Title Of Your Page Goes Here!</title>
</head>
<body>

    <script language="javascript" type="text/javascript">

        function checkCR(evt) {

            var evt = (evt) ? evt : ((event) ? event : null);
            var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
            if ((evt.keyCode == 13) && (node.type == "textarea") && (node.name == "field1"))
 {
                return false;
            }
        }
        document.onkeypress = checkCR;
    </script>

    <p>
        <center>
            <form action="" method="post">
            Enter Your Number<br>
            <textarea cols="40" rows="5" name="field1" wrap="physical"></textarea><br>
            Enter Your Message<br />
            <textarea cols="40" rows="5" name="field2" wrap="physical"></textarea>
            <input type="submit" value="Send it!">
            <input type="reset" value="Clear it!" />
            </form>
        </center>
    </p>
</body>
</html>
Ramesh S 129 Posting Pro

Try to use Menu.FindItem method to search a menu item.

Assume that a menu has the following structure
Home->Music->Classical
Home->Music->Rock

Here Music has two sub menu items.

To remove the 'Classical' sub menu item from 'Music', use the following code

String valuePath1 = "Home/Music";
        MenuItem musicMenuItem = Menu1.FindItem(valuePath1);
        String valuePath2 = "Home/Music/Classical";
        MenuItem item = Menu1.FindItem(valuePath2);
        musicMenuItem.ChildItems.Remove(item);
Ramesh S 129 Posting Pro

Basically an aspx page will have controls like buttons and textboxes associated with them. Also the page will have a class file associated with it to handle the events related to the page.

If you want to create an aspx page dynamically, you cannot maintain the page alignment, controls and events related to the page. And also you cannot create an instance of a web page and dispaly it just like button control.

Although somewhat you can manage to create an aspx page dymaically using StreamWriter classes but it is not adviceable.

Ramesh S 129 Posting Pro

The automatic sorting feature will work only if you bind the GridView with DataSource controls like SqlDataSource and ObjectDataSource. These controls automatically take care binding data with GridView. Therefore the sorting feature also handled automatically by them.

If you bind the GridView with a DataSet , then you need to call DataBind() explicitly method to bind the data source . Therefore you need to write the code to provide sorting feature.

Ramesh S 129 Posting Pro

Yes. I should also have told that the customer have better performance with million of records in my post.

Thanks for your reply.

Ramesh S 129 Posting Pro

Hi Snake,

Sorry it should read as 'I believe 37000 to 50000 records are not too much for a table' in my post.

If you read my post, i actually iterated that an SQL table can have more than a million of table.

Sorry again. It is typo error.

Ramesh S 129 Posting Pro

Are you using Vista and IIS 7 to run your web site.

Is there HRESULT is displayed along with error message. If so, post that message. It will be helpful to identify the issue.

Also visit the following links to have some idea about the issue if you are using Vista

http://support.microsoft.com/kb/942055
http://forums.iis.net/t/1153917.aspx

Ramesh S 129 Posting Pro

Try this code. It will convert the text into TitleCase using JavaScript.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DemoPage21.aspx.cs" Inherits="DemoPage21" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

    <script type="text/javascript" language="javascript">
        function Trim(strIn) {
            strOut = strIn;
            strOut = strOut.replace(/^ */g, "");
            strOut = strOut.replace(/ *$/g, "");
            return strOut;
        }


        function TitleCase(oField) {

            var myValue = oField.value
            var htext = Trim(myValue);
            htext = htext.toLowerCase();

            htext = htext.substr(0, 1).toUpperCase() + htext.substring(1, htext.length);
            for (var i = 1; i < htext.length; i++) {
                if (htext.substr(i, 1) == " ") {
                    while (htext.substr(i, 1) == " ")
                        i++;

                    if (i + 1 < htext.length)
                        htext = htext.substr(0, i) + htext.substr(i, 1).toUpperCase() + htext.substring(i + 1, htext.length);
                    else
                        htext = htext.substr(0, i) + htext.substr(i, 1).toUpperCase();
                }
            }
            return htext;
        }
    
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" onblur="this.value=TitleCase(this);" runat="server" />
      <asp:TextBox ID="TextBox2" runat="server" />

        </div>
    </form>
</body>
</html>
Ramesh S 129 Posting Pro

There is no setting available to display the number to a specific currency format. It is the matter of display in the tool that you are using to view the data.

However you can format the number in SELECT query or format the number in the user interface(like web pages) whaterver currency format you want.

Ramesh S 129 Posting Pro

Yes. The .NET Framework is essential to run your VB.NET/C# programs. It is an executable setup program(.exe) and can be downloaded from Microsoft website.

Ramesh S 129 Posting Pro

Do the other machines have .NET Framework installed?

If not, you need to install the correct version of .NET Framework in that PC in order to run your VB.NET program successully.

Ramesh S 129 Posting Pro

I believe 37000 to 50000 records are too much for a table.

I have seen that some customers are storing more than a million records in a table.

Your database design ensure that normalization techniques to avoid data redundancy.

To improve search performance, you need to create indexes for the columns on which you provided search option.

Please note that some sql server databases used in Microsoft ERP product does not relationships/integrity constraints among the tables. The integrity and relation of the data is validated through front-ent(user interface). But the tables have proper indexes to improve the performance.

sknake commented: MSSQL eats a million records for a snack before breakfast. What are you talking about?! -3
Ramesh S 129 Posting Pro

Ok. So you are trying to call a function in a Module/Form which is defined in a User Control.

You should not call the public method of an UserControl in a Module.

To call the function, you need to instantiate the user control in the module. For example,

Dim  uc1 As UserControl1
 uc1.myFunction()

But this is not the right approach as the user control is GUI component where as the Module is reusable business component.

Ramesh S 129 Posting Pro

There is no such restriction in VB.NET I believe.

You can call public methods of Classes and Modules inside a UserControl.
You need to call them the way you are calling the public methods of Classes and Modules in a Form.

Ramesh S 129 Posting Pro

Try this.

GRANT EXECUTE  ON sp_OACreate to UserLogin
GO

Here UserLogin is the name of the login that you use to connect with database.

Ramesh S 129 Posting Pro

Try like this

SELECT * FROM ClientWHERE (ClientName LIKE 'Anne%') OR (ClientName LIKE '%[ ]Anne%')
ORDER By  PATINDEX ( 'Anne%', ClientName) DESC
, PATINDEX ( '%[ ]Anne%', ClientName)

Here replace the name 'Anne' whatever you want.

Ramesh S 129 Posting Pro

Hi AbhishekGoenka,

Mark this thread as solved if your question is answered.

Ramesh S 129 Posting Pro

As I said in my previous post, give the full physical or absolute path in codebase property and check it.

Physical Path: Enter the path like file:///D:/yourfoldername/vbActiveX.cab

Abosolute Path: You may enter the url like http://www.agoenka.info/vbActiveX.CAB

Also based on the security settings, you may need to give code access permission to the activex control using Code Access Security Policy Tool (Caspol.exe).

Ramesh S 129 Posting Pro

Try something like this

<object id="ctlVBAX" classid="clsid:B7C88829-7BCF-4AB6-95A5-F63ADBEA151A" codebase="file:///C:/Work/vbActiveX.CAB">
                    </object>

Put the name of the folder where you place the activex control in codebase directory.

Ramesh S 129 Posting Pro

Mark this thread 'Solved' if your question is answered.

Ramesh S 129 Posting Pro

You cannot mark Main method as a WebMetho in asp.net web service. The Main method is used in Windows Desktop and Console applications and behave as a startup point. The Web application will not have Main method.

Also please note that the web services are consuemed in other web and desktop applications and not in the web service itself.

Walkthrough: Creating and Using an ASP.NET Web Service in Visual Web Developer

Ramesh S 129 Posting Pro

If the curreny data is a bound column in the GridView, then use the DataFormatString property to format data.

serkan sendur commented: good +8
Ramesh S 129 Posting Pro

Hi Alexpap ,

Post the complete error message. Becuase the error message that you posted is generic for SMO object.

Also Check the following things:

1. Database connection is estabilished before executing 'Create' method for StoredProcedure object by putting a break point.
2. sp.TextBody has correct syntax.

Ramesh S 129 Posting Pro

This error might be accure by varios reasons.

1. Check whether you are trying to upload a document with size more than 4 MB. Refer this link.
2. Also check the size of the ViewState of your page. If the ViewState has a larger size, it might cause this error to occur. Check this thread.

Also check your network connectivity.

Ramesh S 129 Posting Pro

You question has to be more clear.

Without knowing the name, url of the web service, how can you consume it in your application.

A .net web service is deployed in IIS. Therefore if you know the server name and have remote access to that server, find it by opening IIS in the server and browse the web service.

Ramesh S 129 Posting Pro

1. Since the asp.net application runs under ASPNET account, check whether that account has read/write access on .MDB file.
2. Check if the .MDB file has read-only file attribute set. if it is set read-only , remove it.

Ramesh S 129 Posting Pro

Hi daytonasteve,

Mark this thread as solved if your question is answered.

Ramesh S 129 Posting Pro
Ramesh S 129 Posting Pro

The listbox control 'ListBox5' is inside the FormView control.
You should find control in the FormView control not the Page.

So change your code like below...

<script runat="server">

protected void FormView1_ItemInserted(object sender, FormViewInsertedEventArgs e)
{
        ListBox myControl = (ListBox)FormView1.FindControl("ListBox5");
        string urlpart =  myControl.SelectedItem.Text;
        HttpContext.Current.Response.Redirect("thanks" + urlpart + ".aspx");

}
</script>
Ramesh S 129 Posting Pro

If you need read-only access to the data, something often done inside an ASP.NET application, using a DataReader makes sense. For example, you are filling the textboxes/label controls in a page, then you can use data reader.

You can use datasets if you are going to persist the data between postbacks.

Ramesh S 129 Posting Pro

Mark this thread as Solved if your question is answered.

Ramesh S 129 Posting Pro

You cannot customize it to restrict the file type by extension if you use <input type='file'> tag.

But you can validate server side whether the file has the extension of doc, docx and pdf.

Check this link: http://www.codeproject.com/KB/aspnet/netimageupload.aspx

Ramesh S 129 Posting Pro

Set the timeout properties of WCF application to increase the default timeout. This can be done on the client side programmically or with a client side App.Config or a Web.config.

You can configure the OperationTimeout property for Proxy in the WCF client code.

For example

DirectCast(service, IContextChannel).OperationTimeout = New TimeSpan(0, 0, 240)

Refer: http://www.codeproject.com/KB/WCF/WCF_Operation_Timeout_.aspx

Ramesh S 129 Posting Pro

Mark this thread as solved if your question is answered.

Ramesh S 129 Posting Pro

There are some third party code generation tools for asp.net 2.0 in the market. But most of them are develped as a desktop application which will generate asp.net code with layered approach.

Check these links:
http://www.radsoftware.com.au/codegenerator/
http://www.hkvstore.com/aspnetmaker/
http://www.codesmithtools.com/