Hi,
Plzz do check out this site if you need to write code for sending mail in asp.net 2.0
http://www.systemnetmail.com/default.aspx
Bye
Hi,
Plzz do check out this site if you need to write code for sending mail in asp.net 2.0
http://www.systemnetmail.com/default.aspx
Bye
Hi,
I was getting this error when I was trying to call a .NET dll from an ASP page.
The dll was making use of a web service.
And while searching for it I found that if we are making use of a web service from
an asp page, the page tries to create a temporary file in windows\temp directory and because it hasn’t got rights for the same we get the error.
We can resolve it by giving it the appropriate rights for the windows/temp folder
1) Right click the temp folder à Select properties
2) Go to security tab
3) Click on Add and add ASPNET account. ( In locations select your machine )
4) Then add one more account IWAM_D-0824 (i.e. IWAM_YourMachineName)
5) Try running the ASP page again. The page should run without any error.
Bye
Hi All,
To use form authentication in asp.net application
1- Create a new website
2- Change the name of the default.aspx to login.aspx
3- Add 2 labels one for username and password and two textboxes name txtUserName and txtPassword
and a button named btnLogin with label Login.
4 -Put the following in the web.config page
<authentication mode=”Forms”>
<forms loginUrl=”login.aspx”>
<credentials passwordFormat=”Clear”>
<user name=”Mickey” password=”Mouse”/>
</credentials>
</forms>
</authentication>
<authorization>
<deny users=”?”/>
</authorization>
5-Put this code in the btnLogin click’s event handler.
protected void btnLogin_Click(object sender, EventArgs e)
{
if(FormsAuthentication.Authenticate(txtUserName.Text,txtPassword.Text))
{
FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, false);
}
else
{
lblInfo.Text = “you are not authorized to view the page”; // add one more label lblInfo }
}
6- That’s it your page should work now
We can add more users within the credential section of web.config
We can even encrypt the password we are saving in the web.config
We can even make use of cookie for the same.
Looking forward to include the code for the same
Bye
Let’s see how we can use javascript with our server side controls with very simple examples
1) One way is using
controlname.attributes.add(string key,string value);
Let’s see an example
1. Create a new webpage
2. Add a textbox to it.
<asp:TextBox ID=”TextBox1″ runat=”server”></asp:TextBox>
3. Now let us add some javascript for onMouseOver event so that whenever mouse is over the textbox it should alert Hello World message.
4. For this add this code on page_load event handler
protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Attributes.Add(“onMouseOver”,”alert(‘Hello World’);”);
}
OnMouseOver is the name of the JavaScript event followed by our javascript code to run on occurence of that event.
5. If small code of javascript is there than we can write it over directly in attributes.add but otherwise it’s better we write the code within our script block and put the name of the function over there
<script type=”text/javascript”>
function mHover()
{
alert(‘Hello World’);
}
</script>
and
protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Attributes.Add(“onMouseOver”, “mHover()”);
}
Normally we can insert javascript by adding attributes to the control.
But for our button server control we can use OnClientClick property for handling button clicks with Javascript code
<asp:Button ID=”Button1″ runat=”server” Text=”Button” OnClientClick=”return confirm(‘Post back to the server?’);”/>
Whatever is written on OnClientClick fires first followed by the postback event.
In above case if the method returns false i.e. user clicks cancel no post back occurs.
Some common javascript events which we can use inside attributes.add are
onChange, onClick, onMouseOver, onMouseOut, onKeyUp, onKeyDown, onSelect, onFocus, onBlur,onAbort, onError, onLoad ,onUnload
In asp.NET we can make use of Page.ClientScript property for managing script blocks
RegisterClientScriptCallBlock() : It writes the script block right after the <form runat=server> tag
RegisterStartupScript() : It writes the script block right before closing </form> tag
We will modify the textbox example we first created
1: Remove the script section from the aspx page and put it on the page load like this
protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Attributes.Add(“onMouseOver”, “mHover()”);
string script=@”<script type=’text/javascript’>
function mHover()
{
alert(‘Hello World’);
}
</script>”;
Page.ClientScript.RegisterClientScriptBlock(this.GetType(),”onMO”,script);
TextBox1.Attributes.Add(“onMouseOver”, “mHover()”);
}
2: Now run the web page and see the source we will find the script added just after the <form> start tag
3: Now replace
Page.ClientScript.RegisterClientScriptBlock(this.GetType(),”onMO”,script);
with
Page.ClientScript.RegisterStartupScript(this.GetType(),”onMO”,script);
4: We will be able to see the script added just before the </form> tag
Bye
Here we will be calling the default helloworld webservice that is already created for us when we open a asp.net webservice project template in Visual Studio.
We’ll just have a textbox(html control) which will display us the Hello World! response returned from the web service.
This is the step we need to follow
1) Create a new ASP.NET WebApplication
2) Put a html textbox control on the form
<input type=”text” id=”info”/>
3) Put this script code in the head section of the aspx page
<script language=”javascript”>
var xmlHttp;
function getMessage()
{
xmlHttp=new ActiveXObject(“Microsoft.XMLHTTP”);
xmlHttp.open(“post”, “http://localhost/WebService1/Service1.asmx/HelloWorld”, false);
xmlHttp.onreadystatechange=doUpdate;
xmlHttp.send();
return false;
}
function doUpdate()
{
if(xmlHttp.readyState==4)
{
var startTag = “<string xmlns=\”http://tempuri.org/\”>”;
var endTag = “</string>”;
var exch;
var valueStart = 0;
var valueEnd = 0;
valueStart = xmlHttp.responseXML.xml.indexOf(startTag, valueEnd) + startTag.length;
valueEnd = xmlHttp.responseXml.xml.indexOf(endTag, valueEnd+1);
exch = xmlHttp.responseXML.xml.substring(valueStart, valueEnd);
document.forms[0].elements[‘Info’].value=exch;
}
</script>
4) Call the getMessage function in the body’s onLoad eventHandler
<BODY onload=”getMessage()”>
5) Run the applicaton. We’ll see the HelloWorld! text in our textbox(‘info’)
Now let us understand what is happening inside the javascript code
xmlHttp=new ActiveXObject(“Microsoft.XMLHTTP”)
This line of code creates the XMLHttpRequest object. This object sends request to the server and processes the responses from it.
The above code creates the object specific to Internet Explorer( <=6.o).
It is implemented as Active X for IE. However in IE 7 XMLHttpRequest will come as native JavaScript object.
For other browsers we can write
xmlHttp=new XMLHttpRequest();
or best we can write this
if(window.ActiveXObject)
{
xmlHttp=new ActiveXObject(“Microsoft.XMLHTTP”);
}
else if (window.XmlHttpRequest)
{
xmlHttp=new XMLHttpRequest();
}
xmlHttp.open(“post”, “http://localhost/WebService1/Service1.asmx/HelloWorld”, false);
The open method initializes the connection to the server and informs the xmlHttp object how to connect to the server.
post- it indicates how we want to send the data. It can be “get” as well
url- comes the url where we are connecting
false- this means we are making a synchronous call. To make asychronous call simply set it to true
xmlHttp.onreadystatechange=doUpdate;
This specifies the name of the function to be called whenever the state of the xmlHttpRequest changes
xmlHttp.send();
Send method than makes the request to server. This method would return immediately in case of asynchronous call and it would block until the synchronous response is received from the server.
if(xmlHttp.readyState==4)
It tells about the current state of the request
0- uninitialized
1- loading
2- loaded
3-interactive
4-complete
xmlHttp.responseXML.xml
It returns the current response from server in XML=
<?xml version=”1.0″?>
<string xmlns=”http://tempuri.org/”>Hello World !</string>
Than we are using some javascript functions to get the Hello World! and remove everything else.
document.forms[0].elements[‘Info’].value=exch;
Finally assigning the value to our textBox.
The function doUpdate() can be written differently so that we don’t have to make use of any string functions.
function doUpdate()
{
if(xmlHttp.readyState==4)
{
// Here the server is returning us XML in response so we can make use of responseXML
// Here the browser creates a DOM tree to represent that XML and puts a reference to that DOM tree
// in the request’s (xmlHttp) object’s responseXML
var xmlDoc=xmlHttp.responseXML;
var responseElement=xmlDoc.getElementsByTagName(“string”)[0];
var respText=responseElement.firstChild.nodeValue;
document.forms[0].elements[‘Info’].value=respText;
}
However creating a ASP.NET AJAX webservice is little different than our normal ASP.NET web service, and calling them using the ASP.NET AJAX client library is also a bit different
https://nishantrana.wordpress.com/2007/11/06/creating-and-calling-aspnet-ajax-web-service/
Bye
Hi to add rows and columns to Gridveiw dynamically what
we will do is that
1) Create a DataTable object to which than we will bind the GridView
DataTable dt=new DataTable();
2) IF you need two columns than create two DataColumn object
DataColumn dCol1=new DataColumn(FirstC, typeof(System.String)); // string FirstC=”column1″
DataColumn dCol2=new DataColumn(SecondC, typeof(System.String)); // string SecondC=”column2″
Add it to the table
dt.Columns.Add(dCol1);
dt.Columns.Add(dCol2);
3)Run the loop for as many rows you want to add.
// say you want to add two rows
for(int i=0;i<2;i++)
{
DataRow row1 = dt.NewRow();
row1 [FirstC] = “One”;
row1 [SecondC] =”Two”
dt.Rows.Add(row1 );
}
Now iterate through each datacolumn and create a BoundField foreach column
foreach (DataColumn col in dt.Columns)
{
BoundField bField = new BoundField
bField.DataField = col.ColumnName;
bField.HeaderText = col.ColumnName;
GridView1.Columns.Add(bField);
}
GridView1.DataSource = dt;
//Bind the datatable with the GridView.
GridView1.DataBind();