Archive

Archive for February, 2011

Access HTML Controls From code behind

February 28, 2011 Leave a comment

This week i found an interesting logic to get the value of all HTML controls in a form from code behind..
Suitation
I am working on a dynamic form and the form contains no of input controls with unique name..
On the load evnt of page using innerhtml i build the form on the div inputs

Now on submi button click event of this form i need all values of input controls(NOte: There is no runat=”server” attribute with controls)

string value = Request.Form["mycontrol"];
 

this code returns the value of an input control with id [“mycontrol”] and

string[] controls = Request.Form.AllKeys;

this code returns the id of all input controls in the form

Logic here is

loop through all controols and get their values
protected void btnupdate_Click(object sender, EventArgs e)
{

string[] controls = Request.Form.AllKeys;
for (int i = 0; i < controls.Length; i++)
{
string value = Request.Form[controls[i]]; //contains the value of  input control.Before doing this check the controls[i] contains any portion of control name like this if (controls[i].Contains(“tblindustry”)
}

}

Categories: ASP.NET

Using ASP.NET Handler Using jQuery & Ajax With JSON

February 28, 2011 Leave a comment

For last few days i am working on some new(for me) technologies like
using Handlers in ASP.net web applications ..
Call the Handlers using Jquerry and ajax
Return normal text or html formated data from handlers back to web pages as response for ajax calls..
i spend some time- half of a day to get idea on these things and one thing i found is if we want to return more data (eg: details Of a persons based on some search criteria like his name,email,address..etc ) returning text/html is not a good way..
I got the concept Of JSON at this time and i found a good tutorial with sample code here….Here Is Link

Try these if some one needs these
And i create a code of my own that is available here

Categories: ASP.NET

Resize Image Before upload to server

February 19, 2011 Leave a comment

i found a useful link to reduce image size and save on server
This

Categories: Prsnl References

Manipulating datas From gridview

February 12, 2011 Leave a comment


asp:GridView ID="grdSaleList" runat="server" AutoGenerateColumns="false" EmptyDataText="No Files Found"
DataKeyNames="ListFileId,ListFileName" CellPadding="3" CssClass="grid"
onrowcommand="grdSaleList_RowCommand" onrowdatabound="grdSaleList_RowDataBound"

And the screen shot of gridview is

gridview structre

gridview structre


If(!ispostBack)
{
loadGrid(); //write code to fill grid
}

protected void grdSaleList_RowDataBound(object sender, GridViewRowEventArgs e)
{

try
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
ImageButton imgdel = e.Row.FindControl("lnkDelete") as ImageButton;
imgdel.Attributes.Add("onclick", "javascript:return confirm('Are you want To Delete This File'"+DataBinder.Eval(e.Row.DataItem,"Title")+" ?')");

}
}
catch (Exception ex)
{
divErrorMessage.InnerHtml = ex.Message;
}

}

protected void grdSaleList_RowCommand(object sender, GridViewCommandEventArgs e)
{
try
{
string id = e.CommandArgument.ToString();
GridViewRow currentRow = (GridViewRow)((Control)e.CommandSource).NamingContainer;
string fileName = Convert.ToString(grdSaleList.DataKeys[currentRow.RowIndex].Values[1]);
//gets the second keyvalue .In this case first key value is Id
if (e.CommandName == "ViewFile")
{
downloadFile(fileName);
}
if(e.CommandName=="DeleteFile")
{
DeleteListFile(id, fileName);
}
}
catch (Exception ex)
{
divErrorMessage.InnerHtml = ex.Message;
}
finally
{

}
}

Categories: ASP.NET

create and save xml document using c#

February 12, 2011 Leave a comment

The code for creating and saving the xml document is described here..
is all about my experiments (from different sites you may find different approach,but the logic described here is feels good and easy for me)

Namespace you need to use is using System.Xml;

If you use this code
string xmlname = "Files/Form.xml"; //saves the xmlfile in this name in Files Folder OF Applciation make sure this folderis exists
XmlDocument doc = new XmlDocument(); //creates the instance of xmldocument
//For getting the xmlversion informations..not mandatory
XmlNode declaration = doc.CreateNode(XmlNodeType.XmlDeclaration, null, null);
doc.AppendChild(declaration);//Append this node to the document object
//declare root of the xml document and append this to the document object
XmlElement mainRoot = doc.CreateElement("Root");
doc.AppendChild(mainRoot);
doc.Save(xmlname);

you get output as view output1 From image
If you use this code
string xmlname = "Files/Form.xml"; //saves the xmlfile in this name in Files Folder OF Applciation make sure this folderis exists
XmlDocument doc = new XmlDocument(); //creates the instance of xmldocument
//For getting the xmlversion informations..not mandatory
XmlNode declaration = doc.CreateNode(XmlNodeType.XmlDeclaration, null, null);
doc.AppendChild(declaration);//Append this node to the document object
//declare root of the xml document and append this to the document object
XmlElement mainRoot = doc.CreateElement("Root");
doc.AppendChild(mainRoot);
XmlElement childnode = doc.CreateElement("Child1"); //it creates a child node
mainRoot.AppendChild(childnode); //Append childNode to Root OF xmlDocumeet

doc.Save(xmlname);

you get output as view output2 From image
output
If you use this code
XmlElement childnode = doc.CreateElement("Child1"); //it creates a child node string cdatavalue = "This Is Some text inside node"; //assign value needed inside this tag
XmlCDataSection subitem_value = doc.CreateCDataSection(cdatavalue); //create cdata object and store value to cdata object
childnode.AppendChild(subitem_value); //append cdata object to the childnode
mainRoot.AppendChild(childnode); //Append childNode to Root OF xmlDocumeet
//Save Xml Document
doc.Save(xmlname);

you get output as view output3 From image
If you use this code

childnode.InnerText = "This Is Some text inside node";
childnode.InnerXml = "This Is Some text inside node";

you get output as view output4 From image

If you use this code
XmlElement Nextchildnode = doc.CreateElement("Child1"); //it creates a child node
Nextchildnode.InnerXml = "This is second Node"; //we can use innertext also for norma text values
XmlAttribute Attribute = doc.CreateAttribute("Type"); //creates an attribute object
Attribute.Value = "Value Of Attribute"; //fill the value of attribute
Nextchildnode.Attributes.Append(Attribute); //append the attribute to the node
mainRoot.AppendChild(Nextchildnode); //Append childNode to Root OF xmlDocumeet

you get output as view output5 From image

Finaly if u use this section of code

XmlElement Nextchildnode = doc.CreateElement(“Child1”); //it creates a child node
XmlAttribute Attribute = doc.CreateAttribute(“Type”); //creates an attribute object
Attribute.Value = “Value Of Attribute”; //fill the value of attribute
Nextchildnode.Attributes.Append(Attribute); //append the attribute to the node
XmlElement subchilds = doc.CreateElement(“SubChild1”); //it creates a Subchild node
subchilds.InnerXml = “This is first Sub Node”; //we can use innertext also for norma text values
Nextchildnode.AppendChild(subchilds);//Append this node as the child OF Subchild
subchilds = doc.CreateElement(“SubChild2”); //it creates a 2nd Subchild node
subchilds.InnerXml = “This is Second Sub Node”; //we can use innertext also for norma text values
Nextchildnode.AppendChild(subchilds);//Append this node as the child OF Subchild
mainRoot.AppendChild(Nextchildnode); //Append childNode to Root OF xmlDocumeet
//Save Xml Document
doc.Save(xmlname);

You can view an output like this

you get output as view output6 From image

Categories: Xml

A good week 4 me..

February 12, 2011 Leave a comment

Last week is very good for me…One of my dreams for a long time comes to reality..i got a good profile job in an MNC (Fagbokforlaget) as junior software engineer … The post is on their newly opend software section in NewDelhi..Still i did’nt get the detaild offer letter & i am waiting 4 that..I thought its a good chance for me to achieve my career objectives through this company..since its a starting firm and in a hurry to be a part of them..

My interview was on last week (5th feb)and it was one of the best interviews i had ever faced.. .I expect some tough technical and HR related questions but nothing like that happend.All of them are in a friendly mood that release my tension it last for nearly 30 minutes and i am so confident about this job and i got the confirmation from them after 4 days of interview..

****THANK GOD*****

Categories: Prsnl References