Thursday, May 23, 2013

Set and Get Textbox Value inside ascx Control from ASP.NET Page

Setting and getting Textbox value inside user control (ascx control) from aspx page is a usual practice in both simple and complex projects.
In this tutorial, we will
  • Create New User Control.
  • Add User Control in aspx Page.
  • Set Textbox Value inside User Control
  • Get Textbox value From User Control

Create New User Control

  1. Right Click on Project, Click Add New Item.
  2. A pop up window will be opened.
  3. Select Web User Control from list, change its Name to 'myControl' and click Add
  4. Two files will be added with name 'myControl.ascx' and 'myControl.ascx.cs'
Replace the code in 'myControl.ascx' file with following code.
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="myControll.ascx.cs" Inherits="Controls_myControll" %>
<table>
    <tr>
        <td>
            Name :
        </td>
        <td>
            <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
        </td>
    </tr>
    <tr>
        <td>
            Age :
        </td>
        <td>
            <asp:TextBox ID="txtAge" runat="server"></asp:TextBox>
        </td>
    </tr>
    <tr>
        <td>
            Profession :
        </td>
        <td>
            <asp:TextBox ID="txtProfession" runat="server"></asp:TextBox>
        </td>
    </tr>
</table>

Add following code in 'myControl.ascx.cs' File.
    public string Name
    {
        get { return txtName.Text.ToString(); }
        set { txtName.Text = value; }
    }
    public string Age
    {
        get { return txtAge.Text.ToString(); }
        set { txtAge.Text = value; }
    }
    public string Profession
    {
        get { return txtProfession.Text.ToString(); }
        set { txtProfession.Text = value; }

    }

Add User Control in aspx Page

  1. Create New aspx Page with name ‘PageForWebControl’.
  2. Open Design View and drag and drop user control on it. Some code will be added in 'PageForWebControl.aspx' page automatically. 
Page will look like this.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PageForWebControl.aspx.cs" Inherits="PageForWebControl" %>

<%@ Register src="Controls/myControll.ascx" tagname="myControll" tagprefix="uc1" %>

<!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>   
        <uc1:myControll ID="myControll1" runat="server" />   
    </div>
    </form>
</body>
</html>

Set Textbox Value inside User Control

Add following code snippet in Page Load Event of 'PageForWebControl.aspx' page to set Values of Textbox  inside User Control.
// Setting Values in ASCX Control
        myControll1.Name = "Waqas Ali";
        myControll1.Age = "24";
        myControll1.Profession = "Computer Scientist";

Get Textbox value From User Control

Add following code snippet in Page Load Event of PageForWebControl.aspx page to get values of Textbox from User Control.
        string _name = string.Empty;
        int _age = 0;
        string _profession = string.Empty;
// Getting Values from ASCX Control
        _name = myControll1.Name;
        _age = Convert.ToInt32(myControll1.Age);
        _profession = myControll1.Profession;

Now you are all done. Run Project and test your values.

Wednesday, May 22, 2013

Difference Between string and String in C#.NET

There is no different between string and String (System.String). string is an alias for System.String in C#.Net.
They compile to the same code, so no difference at execution time. The complete list of aliases in C#.Net is

object:System.Object 
string:System.String
bool:System.Boolean
byte:System.Byte
sbyte:System.SByte
short:System.Int16
ushort:System.UInt16
int:System.Int32
uint:System.UInt32
long:System.Int64
ulong:System.UInt64
float:System.Single
double:System.Double
decimal:System.Decimal
char:System.Char

Thursday, May 2, 2013

ORA-00254 Error in Archive Control String

Error Code
ORA-00254

Description
Error in archive control string 'string'.

Cause
Possible cause of this error is, the specified archive log location is invalid in the archive command or the LOG_ARCHIVE_DEST initialization parameter.

Action
To fix this issue, check the archive string used to make sure it refers to a valid online device.

reference

ORA-00253 Character Limit String Exceeded by Archive Destination

Error Code
ORA-00253

Description
Character limit string exceeded by archive destination string string.

Cause
Possible cause of this error is, the destination specified by an ALTER SYSTEM ARCHIVE LOG START TO command was too long.

Action
To fix this issue, retry the ALTER SYSTEM command using a string shorter than the limit specified in the error message.

reference

ORA-00252 Log String of Thread String is Empty

Error Code
ORA-00252

Description
Log string of thread string is empty, cannot archive.

Cause
Possible cause of this error is, a log must be used for redo generation before it can be archived. The specified redo log was not been used since it was introduced to the database. However it is possible that instance death during a log switch left the log empty.

Action
To fix this issue, empty logs do not need to be archived. Do not attempt to archive the redo log file.

reference

ORA-00251 LOG_ARCHIVE_DUPLEX_DEST cannot be the Same Destination

Error Code
ORA-00251

Description
LOG_ARCHIVE_DUPLEX_DEST cannot be the same destination as string string.

Cause
Possible cause of this error is, the destination specified by the LOG_ARCHIVE_DUPLEX_DEST parameter is the same as the destination specified by an ALTER SYSTEM ARCHIVE LOG START TO command.

Action
To fix this issue, specify a different destination for parameter LOG_ARCHIVE_DUPLEX_DEST, or specify a different destination with the ALTER SYSTEM command.

reference

ORA-00250 Archiver not Started

Error Code
ORA-00250

Description
Archiver not started.

Cause
Possible cause of this error is, an attempt was made to stop automatic archiving, but the archiver process was not running.

Action
No action required.

reference

ORA-00238 Operation would Reuse a Filename that is Part of the Database

Error Code
ORA-00238

Description
Operation would reuse a filename that is part of the database.

Cause
Possible cause of this error is, the filename supplied as a parameter to the ALTER DATABASE BACKUP CONTROLFILE command or to cfileSetSnapshotName matches the name of a file that is currently part of the database.

Action
To fix this issue, retry the operation with a different filename.

reference

Wednesday, May 1, 2013

ORA-00237 Snapshot Operation Disallowed Control File Newly Created

Error Code
ORA-00237

Description
Snapshot operation disallowed, control file newly created.

Cause
Possible cause of this error is, an attempt to invoke cfileMakeAndUseSnapshot with a currently mounted control file that was newly created with CREATE CONTROLFILE was made.

Action
To fix this issue, mount a current control file and retry the operation.

reference