Monday, July 27, 2009
Read html of any web page
string strResult = readHtmlPage("ANY web page url");
Step 2: Create the function "readHtmlPage"
private String readHtmlPage(string url)
{
String result;
WebResponse objResponse;
WebRequest objRequest = System.Net.HttpWebRequest.Create(url);
objResponse = objRequest.GetResponse();
using (StreamReader sr =
new StreamReader(objResponse.GetResponseStream()))
{
result = sr.ReadToEnd();
// Close and clean up the StreamReader
sr.Close();
}
return result;
}
Friday, July 17, 2009
Check uncheck all checkboxes in a gridview using javascript
Step 1:
Put this script below head tag
<script type="text/javascript" language="javascript">
function changeCheckState(chk)
{
var frm = document.forms[0];
for (i=0; i<frm.length; i++)
{
if (frm.elements[i].id.indexOf('checkBox') != -1)
{
frm.elements[i].checked = chk;
}
}
}
</script>
Step :2
Put this checkbox in header template
<asp:CheckBox ID="checkBox" runat="server" />
Step 3:
Put this checkbox in Itemtemplate
<input id="changeCheckStateId" onclick="changeCheckState(this.checked);" runat="server"
type="checkbox" />
Print the contents of a grid on button click
Put the below mentined script below head tag
script language="javascript" type="text/javascript"
function printDiv() {
//open new window set the height and width =0,set windows position at bottom
var a = window.open ('','','location=1,status=1,scrollbars=1,width=600,height=600');
a.moveTo(0,0);//window.open ('','','left =' + screen.width + ',top=' + screen.height + ',width=400,height=400,toolbar=0,scrollbars=0,status=1');
//write gridview data into newly open window
a.document.write(document.getElementById('<%= Printtbl.ClientID %>').innerHTML);
a.document.close();
a.focus();
//call print
a.print();
a.close();
return false;
}
//
script
Put print button
<asp:Button ID="btnPrint" runat="server" OnClientClick="javascript:return printDiv();"
Text="Print" />
Step 3:
Put the Gridview1 on page
Thursday, July 16, 2009
Masking Ajax UpdateProgress control during page processing
Create stylesheet which will cover the window during page processing
.LodingDivBackClass
{
position:fixed;
top:0px;
bottom:0px;
left:0px;
right:0px;
overflow:hidden;
padding:0;
margin:0;
background-color:#000;
filter:alpha(opacity=50);
opacity:0.5;
z-index:1000;
}
.LoadingDiv
{
position:fixed;
top:30%;
left:43%;
padding:10px;
width:20%;
z-index:1001;
background-color:#fff;
border:solid 1px #000;
}
Step 2:
Put the scriptmanager on top of the page
Put the Updatepanel on page. Put all the controls of page in this updatepanel on any event of these controls you want to show progress image which will mask the window.
Step 3:
Put the UpdateProgress control out of update panel and also provide the image which you want to show as processing.
asp:UpdateProgress ID="uProgress" runat="server" AssociatedUpdatePanelID="UpdatepnlRecord"
ProgressTemplate
div class="LoadingDiv" img runat="server" id="imgLoading" src="~/images/progressbar.gif" /
div
div
ProgressTemplate
asp:UpdateProgress
Masking ajax ModalPopupExtender
Create stylesheet to cover the whole window
style type="text/css"
.modalBackground
{
background-color: black;
opacity: 0.5;
z-index: 1000;
filter: alpha(opacity=50);
}
.processMessage
{
position: fixed;
top: 30%;
left: 43%;
padding: 10px;
width: 14%;
background-color: #fff;
border: solid 1px #000;
}
style
Step 2:
Add your ModalPopupExtender control on page
ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" PopupControlID="pnllinkDoctorName"
Drag="false" TargetControlID="lnkbtnConnectedto" CancelControlID="imgbtnCloseWindow"
DropShadow="false" BackgroundCssClass="modalBackground" runat="server">
/ajaxToolkit:ModalPopupExtende
Step 3:
Add your control which will be shown in popup
asp:Panel ID="pnllinkDoctorName" runat="server" CssClass="processMessage" Width="535px"
Style="display: none; background-"
div
Put what you want to show in popup
/div
/asp:panel
Saturday, July 4, 2009
Highlighting Rows in a GridView
-------------
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load ( object sender, EventArgs e )
{
bindGrid();
}
protected void GridView1_RowDataBound ( object sender, GridViewRowEventArgs e )
{
if ( e.Row.RowType == DataControlRowType.DataRow )
{
if ( e.Row.RowType == DataControlRowType.DataRow )
{
e.Row.Attributes.Add ( "onmouseover", "this.savedColor=this.style.backgroundColor;this.style.backgroundColor='Yellow'" );
e.Row.Attributes.Add ( "onmouseout", "this.style.backgroundColor=this.savedColor;" );
}
}
}
}