May 2007 - Posts
There is a situation where you need both IE versions on the same machine to test your web application. Now you can still run IE6 even if you have IE7 installed on your computer. Just download the file attached and extract it.
Thanks to my friend Hisham for providing this stand alone IE6 version.
Hope this helps.
HC
What is a Postback?
Working with web server controls, each action taken will cause the page to send HTTP POST to itself.
How to know which control caused the postback?
There are two hidden fields which will hold the control id and any extra argument. Once for example, you clicked on a button, a javascript event handler will handle this event. The __doPostBack() function will be fired which will set the control id in __EVENTTARGET hidden field and the arguments in __EVENTARGUMENT and finally it submits the form to the server.
So to know which control caused postback in code behind, you can use
string controlID = Request.Params["__EVENTTARGET"];
if controlID returned "" ( in .NET framework 1.1) you should consider trying
if(Request["BUTTONID"] != null)
{
// button is clicked
}
else
{
// Button is not clicked
}
Where BUTTONID Is the id of the button you are trying to figure if it was clicked or not
Hope this helps,
HC
If you are in a case where you need to access the current page from a function inside a class, You don't have to send the page instance into the function parameter, what you can do is to get it using the HttpContext class inside System.Web namespace;
Before starting just add the fully qualified name
using System.Web;
using System.Web.UI;
Below is the code you can use to get the current page.
public void InjectJavascript()
{
Page mypage = (Page)HttpContext.Current.Handler;
mypage.RegisterStartupScript("alert","<script language=javascript>alert('test')</script>");
}
Whenever you call this function, it will inject javascript function inside the page you are trying to access.
Of course using the HttpContext.Current, you can access Server, Response, Request, Session etc...
HttpContext.Current.Session
Regards,
HC
I was in a process when the need for getting values in the <appSettings> category inside a webservice web.config file which exists on the intranet. If i had the physical file for that webservice, i could impersonate the user and load it inside the XmlDocument and then retrieve the information but due to the fact that the virtual folder is only provided, i had to find a way to get these data. I remembered ADO 2.8 had the stream object which takes the virtual directory as a parameter with 4 other parameters which indeed can solve my problem.
1- We need to Add Reference for Microsoft ActiveX Data Objects 2.8 found in the Com tab.
2- use the below code
// Create instance of the ADODB stream object
ADODB.Stream strm = new ADODB.Stream();
// Set the charset to be ASCII
strm.Charset = "ASCII";
// Open the stream - 1 parameter is the Virtual folder for the webservice, 2- Connect Mode, 3- Stream open options, 4 and 5 are the username and password
strm.Open("url=http://localhost/VBC.SERVICE.V3/web.config",ADODB.ConnectModeEnum.adModeReadWrite, ADODB.StreamOpenOptionsEnum.adOpenStreamUnspecified,"","");
// New XmlDocument Object
XmlDocument mydoc = new XmlDocument();
// Load the web.config data
mydoc.LoadXml(strm.ReadText(Convert.ToInt32(ADODB.StreamReadEnum.adReadAll)));
Hope it will help someone in the future...
Best Regards,
HC