Tuesday, 15 December 2015

How to make textbox, dropdownlist combination control using ajax combobox in asp.net

0

Step 1 :

Add the AjaxControlToolkit Reference to your asp.net website and register its assembly on the required page.

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

Step 2:

Add the ToolkitScriptManager above any ajax tool, using this code,

<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>


Step 3:

Now add the following combobox ajax control, combobox is a combination of textbox and dropdown with all dropdown properties and few additional.

<asp:ComboBox ID="ddlRequestTo" runat="server" DropDownStyle="Simple" AutoCompleteMode="SuggestAppend" CssClass="col-md-9">
</asp:ComboBox>


Some Imp Points :

DropDownStyle :


  • Simple :- Any text is allowed and the list is always displayed.
  • Dropdownlist :- User are not allowed to enter text that does not match an item in the list.
  • DropDown :- (default value), any text is allowed

AutoCompleteMode :


  • Suggest :- The combobox will show the list, highlight the first matched item.
  • Append :- The combobox will append the remainder of the first matched item to the user-typed text and highlight the appended text.
  • None :- (default value), Combobox autocomplete behavior is disable.
  • SuggestAppend :- Both behavior of append and suggest will be applied.

Now, in case if you need to enhance or override the default css of the combobox, you can do it as follows :


For Textbox container use the following id :


.ajax__combobox_textboxcontainer {
}

For textbox container input box

.ajax__combobox_textboxcontainer input {
}


For Dropdown list items :

.ajax__combobox_itemlist {
}


When changing itemlist css do add the !important tag as below :


.ajax__combobox_itemlist {
top: 0px !important;
width: 80% !important;
left: 185px !important;
}



Read More »

Thursday, 10 December 2015

Using ValidatorCalloutExtender to Enhance RequiredFieldValidator to validate.

0

Step 1 : First you require Ajaxtoolkit to be added to your  asp.net toolbox.

Step 2: 
Add the RequiredFieldValidator control from toolbox for textbox control to validate.

Step 3: 
Add the ToolkitScriptManager control from the toolbox just below the form tag.

Step 4:
Use the ValidatorCalloutExtender control from the ajax toolkit tools which you have got after adding ajaxtoolkit.dll to the toolbox.


The code must look like this :

<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>

<span> First Name</span>
<asp:TextBox ID="txtFirstName" runat="server" ></asp:TextBox>
<asp:RequiredFieldValidator ID="rqdFirst" runat="server" ControlToValidate="txtFirstName" ErrorMessage="Enter First name!" Display="None"></asp:RequiredFieldValidator>
<asp:ValidatorCalloutExtender ID="ValidatorCalloutExtender1" runat="server" TargetControlID="rqdFirst">

</asp:ValidatorCalloutExtender>



The output window will look like this :



Read More »

Wednesday, 9 December 2015

How to pass repeater/any control from one page to another in asp.net?

0

Step 1:

 Make two pages, one where the control (repeater) is present and another where you need to transfer it, namely source.aspx and destination.aspx.


Step 2:

At source.aspx page write down your control (repeater) and bind it, in my case i am passing the repeater, so that i could print it on another page, you can have other cases to use this functionality..

So at design page of source.aspx

<asp:Repeater ID="rptSalary" runat="server">
<ItemTemplate>
</ItemTemplate>
</asp:Repeater>

<asp:Button ID="btnPrint" runat="server" Text="Print Slip"

onclick="btnPrint_Click" />


At source.aspx.cs

On button click event at which you need this control (repeater) to move to another page.

protected void btnPrint_Click(object sender, EventArgs e)
{
Server.Transfer("~/destination.aspx");
}



Step 3:

At destination.aspx page add all the css file which you might have used at source.aspx, to get the style as well

At destination.aspx.cs page where we code c#, do the following code to find the specific control (repeater in our case) from the source.aspx page


protected void Page_Load(object sender, EventArgs e)
{
if (this.Page.PreviousPage != null)
{
Control ContentPlaceHolder1 = this.Page.PreviousPage.Master.FindControl("ContentPlaceHolder1");
Repeater rptSalary = (Repeater)ContentPlaceHolder1.FindControl("rptSalary");

}
}

Now, if add this rptSalary instance of repeater to any control on this page, or create that too dynamically as below :


Panel Panel1 = new Panel();
Panel1.Controls.Add(rptSalary);
Page.Controls.Add(Panel1);


Now, we have successfully passed the control to another page.
And yeah if you too want to print this repeater or any specific control from a webpage, then follow this whole procedure and just add one more line to it i.e ,

Response.Write("<script>window.print();</script>");



The whole code for destination.aspx will be;



protected void Page_Load(object sender, EventArgs e)
{
if (this.Page.PreviousPage != null)
{
Control ContentPlaceHolder1 = this.Page.PreviousPage.Master.FindControl("ContentPlaceHolder1");
Repeater rptSalary = (Repeater)ContentPlaceHolder1.FindControl("rptSalary");
Panel Panel1 = new Panel();
Panel1.Controls.Add(rptSalary);
Page.Controls.Add(Panel1);
Response.Write("<script>window.print();</script>");
}
}


Read More »

Tuesday, 8 December 2015

How to open new popup form on gridview button click ?

0


Step 1:

We will use ajaxtoolkit to open a new form on gridview button click or on normal button click.
You have to add reference to AjaxToolKit.dll, which you can found in the package of ajaxtoolkit from ajaxcontroltoolkit.codeplex.com.

Step 2:
You can also add Ajax tools into the asp.net toolbox, and then you can directly use its control from there, or you can hard-code.
 First, Register the DLL if you are preferring hard-code.

 <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>


on design.aspx

<style type="text/css">
.tableBackground
{
background-color:silver;
opacity:0.7;
}
</style>



<asp:ToolkitScriptManager ID="ScriptManager1" runat="server"></asp:ToolkitScriptManager>

<asp:GridView ID="grdView" runat="server" AutoGenerateColumns="False"
onrowcommand="grdView_RowCommand">
<Columns>
<asp:TemplateField HeaderText="Emp Id">
<ItemTemplate>
<asp:Label ID="lblEmpId" runat="server" Text='<%#Eval("empId") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Generate Salary">
<ItemTemplate>
<asp:LinkButton ID="btnGenerateSalary" runat="server" Text="Generate Salary" CssClass="btn btn-info" CommandArgument='<%#Eval("empId") %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

<asp:Button ID="modelPopup" runat="server" style="display:none" />
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="modelPopup" PopupControlID="updatePanel"
CancelControlID="btnCancel" BackgroundCssClass="tableBackground">
</asp:ModalPopupExtender>
<asp:Panel ID="updatePanel" runat="server" BackColor="White" style="display:none">

<div>
<span >Gross Salary</span>
<asp:Label ID="lblGrossSalary" runat="server"></asp:Label>
</div>
<asp:Button ID="btnCancel" runat="server" Text="Close" />

</asp:Panel>

The modalPopExtender will open the panel as a popup form :



on.cs


protected void grdView_RowCommand(object sender, GridViewCommandEventArgs e)
{
string empId = e.CommandArgument.ToString();
this.ModalPopupExtender1.Show();
}

//You can do any implementation here with the help of the empId, or any value that you will pass as commandargument.



Read More »

Thursday, 3 December 2015

How to bind dropdown with multiple columns using entity framework?

0


Problem:

We have to bind the table to the dropdown where we need the complete name as the text value of dropdown and emp_id as datavalue.



The name of dropdownlist is ddlRequestTo and the entity database object named context with tbl_employeePersonal


Solution:

private void bindRequestTo()

{
ddlRequestTo.DataSource = (from emp in context.tbl_employeePersonal select new { FullName = emp.emp_firstName + " " + emp.emp_middleName + " " + emp.emp_lastName, emp.emp_Id}).ToList();
ddlRequestTo.DataTextField = "FullName";
ddlRequestTo.DataValueField = "emp_Id";
ddlRequestTo.DataBind();
ddlRequestTo.Items.Insert(0, "--Send Request To--");
}




Read More »