Oct 20, 2015

Posted in , , , ,

How to Produce Text file in ASP.NET 4.6?

In this example we explain that how to produce text file in ASP.NET 4.6 or write data to the text file fetching from the database.

How to Produce Text file in ASP.NET 4.6?


Here usually we create new file and write data to text file from the database.below is code for creating text file and write data to it.

HostForLIFE.eu

fs1 = new FileStream(Server.MapPath("Files\\demo.txt"), FileMode.OpenOrCreate, FileAccess.Write);

writer.Write("Name :" + Convert.ToString(dtDetails.Rows[0]["name"]) + Environment.NewLine);
    writer.Write("City :" + Convert.ToString(dtDetails.Rows[0]["Clty"]) + Environment.NewLine);
    writer.Write("Country" + Convert.ToString(dtDetails.Rows[0]["Country"]) + Environment.NewLine);
writer.Close();

you can also overwrite the existing file if exist like just write
fs1 = new FileStream(Server.MapPath("Files\\demo.txt"), FileMode.Create);

And here is the output:
How to Produce Text file in ASP.NET 4.6?

Oct 12, 2015

Posted in , , , ,

Binding the Drop Down List Form Database

In the web development the drop down list is most vital tool, we have a tendency to Use several time and lots of places to use this for showing the list in hidden format. And to fill date in to this list, after we need on page the choose a particular item in this drop down list in to ASP.NET code.Now, I want to fill all class names in to drop down list that are store in the data base. For this a have a table that has classes name.

Binding the Drop Down List Form Database

Next step, create a web page. Take a drop down list in to page. Write the following code
<asp:DropDownList ID="ddlclassId"
runat="server" Width="128px" AutoPostBack="True">                     
</asp:DropDownList>

In below code we will give the drop down list id is "ddlclassId" for understanding to drop down. Then go to the coding page and make a function for selecting the value form data base.
private void FillClass()
{
DataSet ds=new DataSet();
ds=objc1.Select_Class();

/*
in the brown color coded part use for fetching data form table in to Dataset use some class file and Store processor for this .if you have other way then put here.
we select two values Class Name and Section Name in Class and Class Id ,Class id is primary key ..
*/

ddlclassId.DataTextField = "Class";
//dataTextField hold those value which are show in list .
ddlclassId.DataValueField = "ClassId";
//dataValueField use for get unicq value of selected item.
ddlclassId.DataBind();
ddlclassId.Items.Insert(0, new ListItem("Select", "0"));
//this line use for inserting "Select" in to list .
}

Call this function in to page load Event .
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
 
    FillClass();
 
}
}
HostForLIFE.eu
After that, "right click" on the design page and view in browser. I hope it works for you!

Oct 6, 2015

Posted in , , , ,

ASP.NET Hosting - How to Hide jQuery Dialog Modal Popup after AJAX Call Success ?

This post is about How to Hide jQuery Dialog Modal Popup after AJAX Call Success.
ASP.NET Hosting

HTML Markup
The below HTML Markup consists of an HTML DIV containing a TextBox to enter some content, a Button for triggering jQuery AJAX call.
<div id="dialog" style="display: none">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
    <td>
        Name:
    </td>
    <td>
        <input type="text" id="txtName" value="" />
    </td>
</tr>
<tr>
    <td colspan="2" align="center">
        <img id="imgLoader" alt="" src="loading.gif" style="visibility: hidden" />
    </td>
</tr>
<tr>
    <td colspan="2" align="right">
        <input type="button" id="btnSubmit" value="Submit" />
    </td>
</tr>
</table>
</div>

The WebMethod
In order to illustrate the functioning, an ASP.Net WebMethod is used which will accept a string value and will simply return Boolean value True in response. A delay of two seconds has been added to experience the process as otherwise the jQuery UI Modal Popup box will hide instantly.
Note: This solution is not restricted only to ASP.Net and it can be easily used for other technologies too.
[System.Web.Services.WebMethod]
public static bool SubmitDetails(string name)
{
//Fake Delay.
System.Threading.Thread.Sleep(2000);
return true;
}

How to Hide jQuery Dialog Modal Popup after AJAX Call Success ?

Inside the jQuery document ready event handler, the jQuery UI Dialog Modal Popup plugin is applied to the HTML DIV and the jQuery UI Dialog Modal Popup box is shown. When the Button is clicked a jQuery AJAX call is made to the WebMethod and the Loading GIF image is displayed.
Once the response is received then inside the success event handler, the jQuery UI Dialog Modal Popup box is closed (hidden).
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/jquery-ui.js" type="text/javascript"></script>
<link href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/themes/blitzer/jquery-ui.css"
rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(function () {
$("#dialog").dialog({
    autoOpen: true,
    modal: true,
    title: "Submit Details"
});
$("#btnSubmit").click(function () {
    $("#imgLoader").css("visibility", "visible");
    $.ajax({
        type: "POST",
        url: "Default.aspx/SubmitDetails",
        data: "{name: '" + $("#txtName").val() + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (r) {
            $("#imgLoader").css("visibility", "hidden");
            $("#dialog").dialog("close");
        }
    });
});
});
</script>