Florence Blogspot about asp.net tutorials and web design and web development

Friday, May 1, 2009

Get the Checkboxlist values using javascript:

Get the Checkboxlist values using javascript:

We cannot get the value of the checkbox in the checkboxlist because it is rendered in the form of table , td, input and the text of the check is like label.

So we need to bind the value of checkbox in the tilte attribute and then we can read the title values using javascript.

<script type="text/javascript">

function IsCheck()

{

var UserID="";

var UserCode=""

var cblist = "ChkBoxListUsers";

var chkList1= document.getElementById(cblist);

var arrayOfCheckBoxes= chkList1.getElementsByTagName("input");

var arrayOfCheckBoxspans= chkList1.getElementsByTagName("span");

var arrayOfCheckBoxLabels= chkList1.getElementsByTagName("label");

var listcount = arrayOfCheckBoxes.length;

for(var i=0;i<arrayOfCheckBoxes.length;i++)

{

if(arrayOfCheckBoxes[i].checked)

{

UserCode += arrayOfCheckBoxspans[i].title + ",";

UserID += arrayOfCheckBoxLabels[i].innerHTML+ ", ";

}

}

window.opener.document.forms[0].HdnSelectedUsers.value=UserCode;

window.opener.document.forms[0].txtSelectedUsers.value=UserID;

window.close();

return false;

}

</script>

Frontend:

<body>

<form id="form1" runat="server">

<div style="text-align: center">

<fieldset class="Fieldset" style="width: 95%" runat="server" id="fsToolDetails">

<legend class="Legend_Text"><strong>User Details</strong></legend>

<table border="0" cellpadding="0" cellspacing="0" style="width: 100%">

<tr>

<td align="center">

<asp:Label ID="Label1" runat="server" Text="SELECT USER" Width="240px" CssClass="Headlabel"></asp:Label></td>

</tr>

<tr>

<td align="left" style="height: 14px">

<asp:Label ID="lblError" runat="server" CssClass="Err_label"></asp:Label></td>

</tr>

<tr>

<td width="100%" align="left" height="150px">

<div align="left" style="width:300px; height: 159px; width: 100%; overflow: auto; padding-top: 1px;

padding-left: 1px">

<asp:CheckBoxList ID="ChkBoxListUsers" runat="server" CssClass="selectBox" Width="500px" RepeatColumns="2" RepeatDirection="Horizontal" OnDataBound="ChkBoxListUsers_DataBound">

</asp:CheckBoxList>

</div>

</td>

</tr>

<tr>

<td align="center">

<asp:Button ID="btnSubmit" Text="Order" runat="server" CssClass="buttons"

Width="57px" />

<asp:Button ID="btnClose" Text="Close" runat="server" CssClass="buttons" Width="54px"

OnClientClick="window.close();" />

</td>

</tr>

<tr>

<td align="center">

</td>

</tr>

</table>

</fieldset>

</div>

<script type="text/javascript">

function IsCheck()

{

var UserID="";

var UserCode=""

var cblist = "ChkBoxListUsers";

var chkList1= document.getElementById(cblist);

var arrayOfCheckBoxes= chkList1.getElementsByTagName("input");

var arrayOfCheckBoxspans= chkList1.getElementsByTagName("span");

var arrayOfCheckBoxLabels= chkList1.getElementsByTagName("label");

var listcount = arrayOfCheckBoxes.length;

for(var i=0;i<arrayOfCheckBoxes.length;i++)

{

if(arrayOfCheckBoxes[i].checked)

{

UserCode += arrayOfCheckBoxspans[i].title + ",";

UserID += arrayOfCheckBoxLabels[i].innerHTML+ ", ";

}

}

window.opener.document.forms[0].HdnSelectedUsers.value=UserCode;

window.opener.document.forms[0].txtSelectedUsers.value=UserID;

window.close();

return false;

}

</script>

</form>

</body>

Codebehind:

protected void Page_Load(object sender, EventArgs e)

{

if(!IsPostBack)

{

btnSubmit.Attributes.Add("onclick", "return IsCheck();");

if( Request.QueryString["CompanyId"] != null && Request.QueryString["CompanyId"] != "")

{

FillUsers(Request.QueryString["CompanyId"]);

}

}

}

private void FillUsers(string CompanyID)

{

BLLPopUpUser ObjPopUpUser = new BLLPopUpUser();

DataSet ds = new DataSet();

ds = ObjPopUpUser.GetUserListfromCompany(CompanyID);

ChkBoxListUsers.DataSource = ds;

ChkBoxListUsers.DataTextField = "CU_UserID";

ChkBoxListUsers.DataValueField = "CU_UserCode";

ChkBoxListUsers.DataBind();

}

protected void ChkBoxListUsers_DataBound(object sender, EventArgs e)

{

CheckBoxList chkList = (CheckBoxList)(sender);

if (Request.QueryString["Users"] != null && Request.QueryString["Users"].ToString() != "")

{

string[] users = Request.QueryString["Users"].ToString().Split(',');

for (int i = 0; i < users.Length; i++)

{

if (chkList.Items.FindByText(users[i]) != null)

{

chkList.Items.FindByText(users[i]).Selected = true;

}

}

}

foreach (ListItem item in chkList.Items)

{

item.Attributes.Add("title", item.Value);

}

}

Sunday, April 5, 2009

Popup reminder on particular time in asp.net

Question::
Hi ,

I have a implementation on reminders scenario on my webpage .It should work like outlook reminders with snooze functionality.i dont no how to starwith it Can any one guide me on this. I am using VS2005 & SQL2005.



Answer 1 :

The delegate is used when you need to access private variables in a method called by an event handler. The bennefit is one javascript that can be attached to multiple elements and each element has its own life cycle and private data.

setTimeout only runs once after a delay miliseconds.

I'm not that great with javascript. I'm great with using the javascript client libraries ( microsoft.ajax.js jquery.js ...) and implementing the ajaxextender control pattern in my own custom controls.



Answer 2:

USe Timer and run it for certain interval .. Store the time in database .for every interval check the time . on time show the pop up..

Or use windows services.


http://www.c-sharpcorner.com/UploadFile/mahesh/window_service11262005045007AM/window_service.aspx



this link has the basic to create a windows service ..

In on_start event you can create a timer which will help to do ur work

Monday, March 16, 2009

saving TreeView's state

I write a general routine that does the state caching, but it was for leaving a page and coming back to it. (i.e., select a node, then click "Edit" -- which shoots you to an "Edit" page that's not in a hidden panel on the same page... after you're done editing, you get Response.Redirect-ed back to the TreeView page and the expand/collapse/selected-node state is all gone... that's the issue this addresses.)

It's implemented in two static methods that I popped into a "TreeViewHelper" static class. Whenever you need to leave the page, call the "StoreTreeViewStateToSession" method. In your method to bind data to your TreeView, call RestoreTreeViewStateFromSession. If there's no stored state, it just returns silently. If there is stored state, it'll restore it (which nodes are expanded and collapsed, and which node is selected).

They use Session state, which seems appropriate since it's obviously by-user, and cross-page. But the Session variable key has the page name embedded in it, which would cause it *not* to work in your solution (since it's a different page trying to restore the state). A minor tweak to this routine would remedy that issue, however. Store as the variable name suffix a "key" common to your PageA, PageB, etc., instead of Request.ServerVariables["path_info"].

Here's the code. I've just recently adapted it from the IEWebControls TreeView add-on (circa .NET 1.0) and updated it to work with the ASP.NET 2.0 TreeView control. It seems to work like a charm:

public static void StoreTreeViewStateToSession(TreeView tvIn)
{
// Takes the TreeView's state and saves it in a Session variable
// Call this method before leaving the page if we expect to be back
string strVarName;
string strList = "";

strVarName = "tv_" + HttpContext.Current.Request.ServerVariables["path_info"];
if (HttpContext.Current.Session[strVarName] + "" != "")
{
HttpContext.Current.Session.Remove(strVarName);
}

StoreTreeViewStateToSession_Recurse(tvIn.Nodes[0], ref strList);

strList = tvIn.SelectedNode.ValuePath + strList;

HttpContext.Current.Session.Add(strVarName, strList);
}


private static void StoreTreeViewStateToSession_Recurse(TreeNode tnIn, ref string strList)
{
if (tnIn.Expanded == true)
{
strList = "," + tnIn.ValuePath + strList;
}
foreach (TreeNode tnCurrent in tnIn.ChildNodes)
{
StoreTreeViewStateToSession_Recurse(tnCurrent, ref strList);
}
}


public static void RestoreTreeViewStateFromSession(TreeView tvIn)
{
// Takes the Session-stored TreeView state and restores it
// to the passed-in TreeView control.
// Call this method on entry to the page. Nothing will
// happen if the variable doesn't exist.
string strVarName;

// See if stored data exists for this treeview
strVarName = "tv_" + HttpContext.Current.Request.ServerVariables["path_info"];
if (HttpContext.Current.Session[strVarName] + "" != "")
{
string strSelectedNodeIndex = "";
foreach (string strCurrent in HttpContext.Current.Session[strVarName].ToString().Split(','))
{
if (strSelectedNodeIndex == "") // First element in list is selected node
{
strSelectedNodeIndex = strCurrent;
}
else
{
try
{
tvIn.FindNode(strCurrent).Expanded = true;
}
catch
{
//eat exception
}
}
}

try
{
// Verify that node exists before setting SelectedNodeIndex
TreeNode tnTest = tvIn.FindNode(strSelectedNodeIndex);

// Select the node (will only happen if it exists)
tvIn.FindNode(strSelectedNodeIndex).Select();

// Ensure the selected node's parent is expanded
((TreeNode)tvIn.FindNode(tvIn.SelectedNode.ValuePath).Parent).Expanded = true;

}
catch
{
// eat exception
}

HttpContext.Current.Session.Remove(strVarName);
}
}



... Hope that helps!!! See my other post on client-side node selection without forcing PostBack (http://forums.asp.net/thread/1452479.aspx) if you're interested in another of my TreeViewHelper tools, which I'm pretty pleased with lately. Microsoft so needs to hire me. ;-)

Friday, March 13, 2009

Ajax PageMethods using JSON (JavaScript Object Notation)

Page Methods

Page methods allow ASP.NET AJAX pages to directly execute a page’s static methods, using JSON (JavaScript Object Notation). JSON is basically a minimalistic version of SOAP, which is perfectly suited for light weight communication between client and server. For more information about how to implement page methods and JSON, take a look at Microsoft’s Exposing Web Services to Client Script in ASP.NET AJAX.

Instead of posting back and then receiving HTML markup to completely replace our UpdatePanel’s contents, we can use a web method to request only the information that we’re interested in:


[WebMethod] public static string GetCurrentDate() { return DateTime.Now.ToLongDateString(); }

Using JSON, the entire HTTP round trip is 24 bytes, as compared to 872 bytes for the UpdatePanel. That’s roughly a 4,000% improvement, which will only continue to increase with the complexity of the page.

Not only has this reduced our network footprint dramatically, but it eliminates the necessity for the server to instantiate the UpdatePanel’s controls and take them through their life cycles to render the HTML sent back to the browser.

Search