Saturday, August 13, 2011

Sending Call back from client side to Server Side without postback by using AJAX(ClientCallBacks)

We can make a call from client side to server side without postback
occurance by using "AJAX".
To achieve "Call back" concept in ASP.NET web page. we need to perform
the following steps:
Serverside:
=======
1. Need to Implement "System.Web.UI.ICallbackEventHandler" for your web page.
2. Need to Implement "RaiseCallBackEvent" method for the
"ICallBackEventHandler" interface. This method is called by the
clientside. You can use it to receive parameter values from the
client.
3.Need to Implement "GetCallBackResult" method for
"ICallBackEventHandler" interface. This function will returns the
result of any serverside process to clientside. The results are sent
as a string back to the client code.

Default.aspx:
=========
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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>Untitled Page</title>
<script language="javascript" type="text/javascript">
function ClientCallbackFunction(args) {
LabelMessage.innerHTML=args;
}

</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList runat="server" ID="dllChoice"
onchange="MyServerCall(dllChoice.value)">
<asp:ListItem Text="09">
</asp:ListItem>
<asp:ListItem Text="01">
</asp:ListItem>
<asp:ListItem Text="02">
</asp:ListItem>
<asp:ListItem Text="03">
</asp:ListItem>
<asp:ListItem Text="04">
</asp:ListItem>
<asp:ListItem Text="05">
</asp:ListItem>

</asp:DropDownList>

<asp:Label runat="server" ID="LabelMessage" ></asp:Label>
</div>
</form>
</body>
</html>



Default.aspx.cs:
===========
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public partial class _Default :
System.Web.UI.Page,System.Web.UI.ICallbackEventHandler
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
}
string callbackRef =
Page.ClientScript.GetCallbackEventReference(this, "args",
"ClientCallbackFunction", "");
string callbackscript = "function MyServerCall(args)" + "{" +
callbackRef + "; }";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(),
"MyServerCall", callbackscript, true);

}
string _callBackEventArgs;
public void RaiseCallbackEvent(string eventArgument)
{
_callBackEventArgs = eventArgument;
}
public string GetCallbackResult()
{
return _callBackEventArgs;
}
}







Example2:
=======



<%@ Page Language="C#" AutoEventWireup="true"  %>
<%@ Implements Interface="System.Web.UI.ICallbackEventHandler" %>

<!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>Client Callbacks</title>
    <script runat="server">
        public void RaiseCallbackEvent(String eventArgument)
        {
            // Processes a callback event on the server using the event
            // argument from the client.
        }

        public string GetCallbackResult()
        {
            // Returns the results of a callback event to the client.
            string dateString = DateTime.Now.ToLongDateString();

            return dateString;
        }

        void Page_Load(object sender, EventArgs e)
        {
            ClientScriptManager cm = Page.ClientScript;
            String cbReference = cm.GetCallbackEventReference(this, "arg",
                "ReceiveServerData", "");
            String callbackScript = "function CallServer(arg, context) {" +
                cbReference + "; }";
            cm.RegisterClientScriptBlock(this.GetType(),
                "CallServer", callbackScript, true);
        }
    </script>
    <script type="text/javascript">
        function ReceiveServerData(arg, context) {
            Message.innerText = "Date from server: " + arg;
        }
    </script>
</head>
<body>
    <h2>Client Callbacks Without Postbacks</h2>
    <form id="form1" runat="server">
       <input type="button" value="Callback"
           onclick="CallServer('1', alert('Callback sent to Server'))" />
       <br />
       <span id="Message"></span>
   </form>
</body>
</html>

Reference: Callbacks Reference
Example3
--
Regards:
M.Rama Subba Reddy
Cell:+919080391242


























Friday, August 5, 2011

How to access Div tag in Asp.NET Themes and Skins

you can use <asp:panel, it will become <div> after rendering.
Try this
skinfile.skin  inside App_Themes/Theme1 folder

<asp:Panel runat="server" SkinId="panelSkinned" BackColor="Red" ></asp:Panel>
yourpage.aspx
<%@ Page Language="C#" AutoEventWireup="true" Theme="Theme1" ...
<asp:Panel ID="test" SkinID="panelSkinned" runat="server" >
hello hai........ :)
</asp:Panel>

html after rendering(yourpage.aspx) :
============================
<div id="test" style="background-color:Red;">
 
        hello hai........ :)
  </div>
Hope this may help

Tuesday, August 2, 2011

Using parent page properties in user control


http://weblogs.asp.net/gunnarpeipman/archive/2008/05/21/using-parent-page-properties-in-user-control.aspx


Using parent page properties in user control

There may be situations when we need to use parent page properties from user control. I know, this situations is a warning sign - there's something wrong with UI structure if user controls should know their parents. So, how to get correct reference to parent page so we can use also custom properties defined there?

Let's suppose we have property called MyId in parent page of our user control and we want to call this property from user control.

If we use this code in our user control


protected void MyMethod()
{
    Page myParent = this.Page;

...
    // here we need to call MyID property
}

we will get just a Page - the base class for all Pages. This is because reference of Page is kept in base class of user controls. Whenever you create a user control it gets also the Page property. But every page we create is custom page that inherits the Page class and we may define our own custom properties.

If we have page called MyPage and it has property MyID then how can we refer to this ID? Solution is simple: we have to use casting.

 

After casting parent page to correct type we are able to use it's properties.




Sunday, July 10, 2011

How to Get return value or any value from server side (Code behind) to client side(Javascript) by using AJAX page method concept:

We can Get Return value or any value from to server side (Code behind) to client side(Javascript) by using AJAX page method concept:

Place script manager in a webpage  and
Here we need to enable "EnablePageMethods" Property of ScripManager.


 <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" >
    </asp:ScriptManager>

Then we need to attach event to the particular return value function


Default.aspx:
==========

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SearchUser.aspx.cs" Inherits="Wizard.SearchUser" %>

<!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 ValidateEmailAddress_Result(ResultString) 

       {
           var emailAddressErrMsg = document.getElementById("emailAddressErrMsg");
           var btnNextAdd = document.getElementById('<%=btnNext.ClientID %>'); 
           var emailAddressExist = ResultString;
           if (emailAddressExist == 1) 
           {
               emailAddressErrMsg.innerHTML = "Entered email address Already exist.";
               emailAddressErrMsg.style.display = 'inline';
               btnNextAdd.disabled = true;
              
           }
           else 
           {
               emailAddressErrMsg.style.display = 'none';
               btnNextAdd.disabled = false;
           }
       }

        function CheckEmailAddress(src) 
        {
            PageMethods.ValidateEmailAddress(src.value, ValidateEmailAddress_Result);
        }
</script>

</head>
<body>
    <form id="form1" runat="server">
 <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" >
    </asp:ScriptManager>
    <div>
     
 <asp:TextBox runat="server" ID="txtEmailAddress" Width="250px" 
 AutoCompleteType="Email"  onBlur="CheckEmailAddress(this);"></asp:TextBox>
 <div class="errMessage" id="emailAddressErrMsg" style="display:none;">
                                    *Please enter a Email Address.
                                    </div>

<asp:Button ID="btnNext" runat="server" Text="Submit"  />
    </div>
    </form>
</body>
</html>

Default.aspx.cs:
===========

[System.Web.Services.WebMethod]
        public static int ValidateEmailAddress(string emailAddress)
        {
            try
            {
                int emailAddresscount = CheckEmailAddressExist(emailAddress);
                if (emailAddresscount > 0)
                {
                    return 1;
                }
                else
                {
                    return 0;
                }
            }
            catch { return 0; }
        }

How to send control value or any value from client side(Javascript) to server side (Code behind) by using AJAX page method concept:

We can send control value or any value from client side(Javascript) to server side (Code behind) by using AJAX page method concept:

Place script manager in a webpage  and
Here we need to enable "EnablePageMethods" Property of ScripManager.


 <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" >
    </asp:ScriptManager>


Default.aspx:
==========

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SearchUser.aspx.cs" Inherits="Wizard.SearchUser" %>

<!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 startSearch(val) {
    
            PageMethods.SendValueToServerSide(val);


        }
</script>

</head>
<body>
    <form id="form1" runat="server">
 <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" >
    </asp:ScriptManager>

    <div>
     
        <asp:TextBox ID="txtval" runat="server"></asp:TextBox>

<asp:Button ID="btnSearchInput" runat="server" Text="SendSearchInput" OnClientClick="
startSearch('

txtval.value'
)
" />
    </div>
    </form>
</body>
</html>

Default.aspx.cs:
===========

[System.Web.Services.WebMethod]


  public static void SendValueToServerSide(string  clientsidevalue)
  {      
        string searchinputfromclientside = clientsidevalue;
  }
  

{Solution}:Login page not redirecting after login in firefox 5 Showing Empty Page

Login page not redirecting after login to destination page. It was showing Empty Page like "Authentication.aspx". then it showing blank page

Here is the solution for the "Url Redirection after Login success"

Solutions is We need to clear that  Cache of particular Repose header of a request by using 

"context.Response.Cache.SetExpires(DateTime.Now);"

Example:
=======

public static void AuthenticateUser(HttpContext context)
{
    if (context.Session["loggedin_user_cst_key"] == null)
    {
      context.Response.Cache.SetExpires(DateTime.Now);
      context.Response.Redirect("Authentication.aspx", false);
    }
}





if any querys contact at ramasubbareddymca@gmail.com

Friday, June 24, 2011

Select rows in dataset table based on other dataset table


Select rows in dataset table based on other dataset table

Navigating a Relationship Between Tables 

One of the primary functions of a DataRelation is to allow navigation from one DataTable to another within a DataSet. This allows you to retrieve all the related DataRow objects in one DataTable when given a single DataRow from a related DataTable. For example, after establishing a DataRelation between a table of customers and a table of orders, you can retrieve all the order rows for a particular customer row using GetChildRows.
The following code example creates a DataRelation between the Customers table and the Orders table of a DataSetand returns all the orders for each customer.

C++
F#
JScript
DataRelation customerOrdersRelation =
    customerOrders.Relations.Add("CustOrders",
    customerOrders.Tables["Customers"].Columns["CustomerID"],
    customerOrders.Tables["Orders"].Columns["CustomerID"]);

foreach (DataRow custRow in customerOrders.Tables["Customers"].Rows)
{
    Console.WriteLine(custRow["CustomerID"].ToString());

    foreach (DataRow orderRow in custRow.GetChildRows(customerOrdersRelation))
    {
        Console.WriteLine(orderRow["OrderID"].ToString());
    }
}

The next example builds on the preceding example, relating four tables together and navigating those relationships. As in the previous example, CustomerID relates the Customers table to the Orders table. For each customer in theCustomers table, all the child rows in the Orders table are determined, in order to return the number of orders a particular customer has and their OrderID values.
The expanded example also returns the values from the OrderDetails and Products tables. The Orders table is related to the OrderDetails table using OrderID to determine, for each customer order, what products and quantities were ordered. Because the OrderDetails table only contains the ProductID of an ordered product, OrderDetails is related to Products using ProductID in order to return the ProductName. In this relation, the Products table is the parent and the Order Details table is the child. As a result, when iterating through the OrderDetails table, GetParentRow is called to retrieve the related ProductName value.
Notice that when the DataRelation is created for the Customers and Orders tables, no value is specified for thecreateConstraints flag (the default is true). This assumes that all the rows in the Orders table have a CustomerID value that exists in the parent Customers table. If a CustomerID exists in the Orders table that does not exist in theCustomers table, a ForeignKeyConstraint causes an exception to be thrown.
When the child column might contain values that the parent column does not contain, set the createConstraints flag tofalse when adding the DataRelation. In the example, the createConstraints flag is set to false for the DataRelationbetween the Orders table and the OrderDetails table. This enables the application to return all the records from theOrderDetails table and only a subset of records from the Orders table without generating a run-time exception. The expanded sample generates output in the following format.

Customer ID: NORTS
        Order ID: 10517
              Order Date: 4/24/1997 12:00:00 AM
                 Product: Filo Mix
                Quantity: 6
                 Product: Raclette Courdavault
                Quantity: 4
                 Product: Outback Lager
                Quantity: 6
        Order ID: 11057
              Order Date: 4/29/1998 12:00:00 AM
                 Product: Outback Lager
                Quantity: 3
The following code example is an expanded sample where the values from the OrderDetails and Products tables are returned, with only a subset of the records in the Orders table being returned.

C++
F#
JScript
DataRelation customerOrdersRelation =
    customerOrders.Relations.Add("CustOrders",
    customerOrders.Tables["Customers"].Columns["CustomerID"],
    customerOrders.Tables["Orders"].Columns["CustomerID"]);

DataRelation orderDetailRelation =
    customerOrders.Relations.Add("OrderDetail",
    customerOrders.Tables["Orders"].Columns["OrderID"],
    customerOrders.Tables["OrderDetails"].Columns["OrderID"], false);

DataRelation orderProductRelation =
    customerOrders.Relations.Add("OrderProducts",
    customerOrders.Tables["Products"].Columns["ProductID"],
    customerOrders.Tables["OrderDetails"].Columns["ProductID"]);

foreach (DataRow custRow in customerOrders.Tables["Customers"].Rows)
{
    Console.WriteLine("Customer ID: " + custRow["CustomerID"]);

    foreach (DataRow orderRow in custRow.GetChildRows(customerOrdersRelation))
    {
        Console.WriteLine("  Order ID: " + orderRow["OrderID"]);
        Console.WriteLine("\tOrder Date: " + orderRow["OrderDate"]);

        foreach (DataRow detailRow in orderRow.GetChildRows(orderDetailRelation))
        {
            Console.WriteLine("\t Product: " +
                detailRow.GetParentRow(orderProductRelation)["ProductName"]);
            Console.WriteLine("\t Quantity: " + detailRow["Quantity"]);
        }
    }
}