How To Access One UserControl from Another UserControl Using ASP.NET

April 26, 2012 Leave a comment

User control 1
==========

<%@ Control Language=”C#” AutoEventWireup=”true” CodeBehind=”UC1.ascx.cs” Inherits=”UC.UC1″ %>

<asp:DropDownList ID=”DropDownList1″ runat=”server” AutoPostBack=”True” OnSelectedIndexChanged=”DropDownList1_SelectedIndexChanged”>
<asp:ListItem>Select</asp:ListItem>
<asp:ListItem>test1</asp:ListItem>
<asp:ListItem>test2</asp:ListItem>
<asp:ListItem>test3</asp:ListItem>
<asp:ListItem>test5</asp:ListItem>
</asp:DropDownList>

uSer control 1 Codebehind
===================
if (!Page.IsPostBack) { }

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
//reaching to get the _Page reference with NamingContainer Property and using FindControl method to get the Label
//DropDownList1.NamingContainer will give reference of the UserControl1′s instance reference on the page
//DropDownList1.NamingContainer.NamingContainer will give reference of the _Page’s reference
//Using FindControl Method to find UserControl – Control2
//again using FindControl Method to find Label inside UserControl – Control2
((Label)((UserControl)((Panel)DropDownList1.NamingContainer.NamingContainer.FindControl(“Panel1″)).FindControl(“uctxtget”)).FindControl(“Label1″)).Text = DropDownList1.SelectedItem.Text;
}

User control 2
==========
<asp:Label ID=”Label1″ runat=”server” Text=”Label”></asp:Label>

Now in aspx page
============

<%@ Register src=”~/UC1.ascx” TagName=”userone” TagPrefix=”uc1″ %>
<%@ Register src=”~/UC2.ascx” TagName=”usertwo” TagPrefix=”uc2″ %>

<body>
<form id=”form1″ runat=”server”>
<div>

<asp:Panel ID=”Panel1″ runat=”server”>
<uc1:userone id=”uctxtgive” runat=”server”></uc1:userone>
<uc2:usertwo id=”uctxtget” runat=”server”></uc2:usertwo>
</asp:Panel>

</div>

</form>
</body>

Cheers :)

Categories: Asp.Net

Insert data using store procedure use scope Identuty in Asp.net

April 26, 2012 Leave a comment

Create as procedure,

CREATE Procedure spinsertdata
@Firstname varchar(100),
@Lastname varchar(100),
@activate bit,
@ident int OUTPUT
as
Insert into tablename
(Firstname,Surname,activate)
values(@Firstname,@Surname,@activate)
SET @Ident = SCOPE_IDENTITY()

Call below function in your code behind:
————————————————-

public bool SPToExecute(string SPName, SqlParameter[] Param)
{
String connectionString = ConfigurationSettings.AppSettings.Get(“ConnectStr”);
SqlConnection cn = new SqlConnection(connectionString);
SqlCommand objCmd = new SqlCommand();
objCmd.Connection = cn;
objCmd.CommandType = CommandType.StoredProcedure;
objCmd.CommandText = SPName;
for (int index = 0; index <= Param.Length – 1; index++)
{
objCmd.Parameters.Add(Param[index]);
}
if (cn.State != ConnectionState.Open)
{
cn.Open();
}
try
{
objCmd.ExecuteNonQuery();
return true;
}
catch (Exception ex)
{
return false;
}
finally
{
if (cn.State == ConnectionState.Open)
{
cn.Close();
}
}
}

===========
private void Insertdata()

{
SqlParameter[] param = new SqlParameter[4];
param[0] = new SqlParameter(“@Firstname”, SqlDbType.VarChar);
param[0].Value = txtfirstname.Text;
param[1] = new SqlParameter(“@Lastname”, SqlDbType.VarChar);
param[1].Value = txtlastname.Text;
param[2] = new SqlParameter(“@Activate”, SqlDbType.Bit);
param[2].Value =0;
param[3] = new SqlParameter(“@ident”, SqlDbType.Int);

param[3].Direction = ParameterDirection.Output;
Boolean res = SPToExecute(“spinsertdata ”, param);

if(res)
{
goto endfun;
}
endfun: ;
}

 

Categories: Asp.Net, SQL

Edit, Update,Delete using GridView in asp.net

April 26, 2012 Leave a comment

Hi,

Please paste this html code in .aspx file b/w body tag.

<asp:Label ID=”lblMessage” runat=”Server” ForeColor=”Red”></asp:Label>

<asp:GridView ID=”GridView1″ runat=”Server” AutoGenerateColumns=”False” BorderWidth=”1″ DataKeyNames=”ident” AutoGenerateEditButton=”false” OnRowEditing=”EditRecord” OnRowCancelingEdit=”CancelRecord” OnRowUpdating=”UpdateRecord” CellPadding=”4″ HeaderStyle-HorizontalAlign=”left” OnRowDeleting=”DeleteRecord” RowStyle-VerticalAlign=”Top” ForeColor=”#333333″ GridLines=”None”>

<Columns>

<asp:BoundField DataField=”Ident” HeaderText=”ident” ReadOnly=”True” />

<asp:TemplateField HeaderText=”Firstname”>

<ItemTemplate>

<%# Eval(“firstname”) %>

</ItemTemplate>

<EditItemTemplate>

<asp:TextBox ID=”txtPageName” runat=”Server” Text=’<%# Eval(“firstname”) %>’ Columns=”30″></asp:TextBox>

<asp:RequiredFieldValidator ID=”req1″ runat=”Server” Text=”*” ControlToValidate=”txtPageName”></asp:RequiredFieldValidator>

</EditItemTemplate>

</asp:TemplateField>

<asp:TemplateField HeaderText=”lastname”>

<ItemTemplate>

<%# Eval(“lastname”)%>

</ItemTemplate>

<EditItemTemplate>

<asp:TextBox ID=”txtPageDesc” runat=”Server” Rows=”10″ Columns=”50″

Text=’<%# Eval(“lastname”) %>’></asp:TextBox>

<asp:RequiredFieldValidator ID=”req2″ runat=”Server” Text=”*” ControlToValidate=”txtPageDesc”></asp:RequiredFieldValidator>

</EditItemTemplate>

</asp:TemplateField>

<asp:TemplateField HeaderText=”Activate”>

<ItemTemplate>

<%# Eval(“Activate”) %>

</ItemTemplate>

<EditItemTemplate>

<asp:DropDownList ID=”dropActive” runat=”server” SelectedValue=’<%# Eval(“Activate”).ToString().ToLower().Equals(“true”) ? “True” : “False” %>’>

<asp:ListItem Text=”Yes” Value=”True”></asp:ListItem>

<asp:ListItem Text=”No” Value=”False”></asp:ListItem>

</asp:DropDownList>

</EditItemTemplate>

</asp:TemplateField>
<asp:TemplateField HeaderText=”Edit”>

<ItemTemplate>

<asp:ImageButton ID=”lnkE” runat=”server” ImageUrl=”~/images.jpg” CommandName=”Edit” />

 

</ItemTemplate>
<EditItemTemplate>
<asp:ImageButton ID=”ImageButton1″ runat=”server” ImageUrl=”~/update.jpg” CommandName=”update” />
<asp:ImageButton ID=”ImageButton2″ runat=”server” ImageUrl=”~/cancel.jpg” CommandName=”cancel” />
</EditItemTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText=”Delete?”>

<ItemTemplate>

<span onclick=”return confirm(‘Are you sure to Delete the record?’)”>

<asp:ImageButton ID=”lnkB” runat=”server” ImageUrl=”~/del.jpg” CommandName=”Delete” />

</span>

</ItemTemplate>

</asp:TemplateField>

</Columns>

<FooterStyle BackColor=”#990000″ Font-Bold=”True” ForeColor=”White” />

<RowStyle BackColor=”#FFFBD6″ ForeColor=”#333333″ VerticalAlign=”Top” />

<SelectedRowStyle BackColor=”#FFCC66″ Font-Bold=”True” ForeColor=”Navy” />

<PagerStyle BackColor=”#FFCC66″ ForeColor=”#333333″ HorizontalAlign=”Center” />

<HeaderStyle BackColor=”#990000″ Font-Bold=”True” ForeColor=”White” HorizontalAlign=”Left” />

<AlternatingRowStyle BackColor=”White” />

</asp:GridView>

 

Code behind
===========

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data.Common;

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{

BindDatas();
}
}

private void BindDatas()
{
SqlConnection objCon = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["conn"]);
SqlCommand sqlcmd = new SqlCommand(“select top 20 ident,firstname,lastname,Activate from dbo.tblAccount “, objCon);
DataSet dSet = new DataSet();
SqlDataAdapter objda = new SqlDataAdapter();
objda.SelectCommand = sqlcmd;
objda.Fill(dSet);

try
{
if (dSet.Tables[0].Rows.Count > 0)
{
GridView1.DataSource = dSet.Tables[0];
GridView1.DataBind();
}

}
catch (Exception ee)
{
lblMessage.Text = ee.Message.ToString();
}
finally
{

dSet.Dispose();

objda.Dispose();

objCon.Close();

objCon.Dispose();

}

}

 

protected void EditRecord(object sender, GridViewEditEventArgs e)
{

GridView1.EditIndex = e.NewEditIndex;

BindDatas();

}
protected void CancelRecord(object sender, GridViewCancelEditEventArgs e)
{

GridView1.EditIndex = -1;

BindDatas();

}

protected void UpdateRecord(object sender, GridViewUpdateEventArgs e)
{

GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];

int autoid = Int32.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString());

TextBox tPageName = (TextBox)row.FindControl(“txtPageName”);

TextBox tPageDesc = (TextBox)row.FindControl(“txtPageDesc”);

DropDownList dActive = (DropDownList)row.FindControl(“dropActive”);

SqlConnection objCon = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["conn"]);

SqlCommand dCmd = new SqlCommand();

try
{

objCon.Open();

dCmd.CommandText = “spUpdateData”;

dCmd.CommandType = CommandType.StoredProcedure;

dCmd.Parameters.Add(“@ident”, SqlDbType.Int).Value = autoid;

dCmd.Parameters.Add(“@firstname”, SqlDbType.VarChar, 50).Value = tPageName.Text.Trim();

dCmd.Parameters.Add(“@lastname”, SqlDbType.VarChar, 500).Value = tPageDesc.Text.Trim();

dCmd.Parameters.Add(“@Activate”, SqlDbType.Bit).Value = bool.Parse(dActive.SelectedValue);

dCmd.Connection = objCon;

dCmd.ExecuteNonQuery();

lblMessage.Text = “Record Updated successfully.”;

// Refresh the data

GridView1.EditIndex = -1;

BindDatas();

}

catch (SqlException ee)
{

lblMessage.Text = ee.Message;

}

finally
{

dCmd.Dispose();

objCon.Close();

objCon.Dispose();

}

 

}

protected void DeleteRecord(object sender, GridViewDeleteEventArgs e)
{

string autoid = GridView1.DataKeys[e.RowIndex].Value.ToString();

 

SqlConnection objCon = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["conn"]);

SqlCommand dCmd = new SqlCommand();

try
{

objCon.Open();

dCmd.CommandText = “spDeleteData”;

dCmd.CommandType = CommandType.StoredProcedure;

dCmd.Parameters.Add(“@AutoID”, SqlDbType.Int).Value = Int32.Parse(autoid);

dCmd.Connection = objCon;

dCmd.ExecuteNonQuery();

 

lblMessage.Text = “Record Deleted successfully.”;

 

// Refresh the data

BindDatas();

 

}

catch (SqlException ee)
{

lblMessage.Text = ee.Message;

}

finally
{

dCmd.Dispose();

objCon.Close();

objCon.Dispose();

}

}

Please change the select query, create the Store procedure for update and delete, Also the parameters.

Hope this helps!

Cheers :)

 

Categories: Asp.Net Tags:

Is it possible to post products to amazon MWS using Classic Asp?

April 7, 2012 Leave a comment

In Short: No, We can’t post product feed to amazon MWS using Classic Asp ( To sell in Amazon )

Reason: We need to post the product feed to Amazon by creating a XML, But while posting the feed we need to convert the XML to base-64( MD5), When we convert using classic asp, This will convert in base 32, But Amazon expects in base 64. So the MD5 will miss match between our MD5 and the Amazon md5 for our feed.

Suggestion: Use PHP to post product to amazon, i.e Post your  ”feed” and “action”  to PHP page using POST method and receive the “feed” and “action”, Now post the feed and action to the Amazon  get back the response in asp page.

Regarding fetching the order details ,item details ,  Getting the FeedSubmissionResult from amazon, We can done this using Classic Asp itself.

This idea may help you!

Note: I am preparing the sample to post products to Amazon from classic asp with a help of a php page. I will post it ASAP

Categories: Asp

adodb.connection error ‘800a0e7a’ provider cannot be found. it may not be properly installed

July 22, 2011 Leave a comment

When running classic ASP on IIS7 on 64-bit server the following error might occur:

adodb.connection error ‘800a0e7a’ provider cannot be found. it may not be properly installed

I got the error when trying to open an excel sheet using [Provider=Microsoft.Jet.OLEDB.4.0;Data Source=file.xsl; Jet OLEDB:Engine Type=5;Extended Properties="Excel 8.0;IMEX=1"]

So what’s the problem?

The IIS application pool needs some configuration to allow 32-bit applications.

  • In IIS Manager, right click the application pool of your app and select Advanced Settings.
  • Set the Enable 32-Bit Applications value to True (See image below)
  • Click OK
  • Done, try again
Enable 32-Bit Applications In IIS7

Enable 32-Bit Applications In IIS7

All the best:)

Categories: Asp

IE9 Fix for cufon Text

May 21, 2011 Leave a comment

Hi Friends,
The sites with Cufon text will not work in IE9, unless we upgrade our coufon.js script file. i.e  We need to replace the script with latest cufon.js. New updated script works fine in all browsers. Click the below link for updated cufon.js.
Download new cufon js for IE9

All the Best.

image align center without using position,margin and padding

December 28, 2010 Leave a comment

Hai,
Copy paste the “head” to “head” tag for Styles
<head>
#container{
width:200px;
height:200px;
border:dotted;
display:table;

}
#Cell{
display:table-cell;
vertical-align:middle;
text-align:center;
}

</ head>

Copy paste the “body” to “body” tag to your html file..
<body>
<div id=”container”>
<div id=”Cell”>
<img src=”image-name.png” alt=”" />
</div>
</div>
</body>

Hope you like this………:)

Categories: Html - Css
Follow

Get every new post delivered to your Inbox.