|
hi there,
i want to handle Close event of my web browser.
if any one close the browser by using [X] button then i need to execute some code.
I can do it using Page_Unload event but for that i need to repeate same code on each page.
Can i catch the browser closing event in Gobal.ASAX...
so i define code only once ....?
Hope i clear what i want.......
Thanks in advance
koolprasad2003
Rating always..... WELCOME
Be a good listener...Because Opprtunity knoughts softly...N-Joy
|
|
|
|
|
koolprasad2003 wrote: t but for that i need to repeate same code on each page
If you are using master pages in your application, you wont have to write same code on each page.
On other thought, you can create a base page and write code to inject javascript function using ScriptManager. And then make all pages to inherit the base class.
|
|
|
|
|
There is no any permanent connection between your browser
and the server.
So you need to detect browser close event from client side (browser) and
then call server event to execute your code.
You can use master page to avoid writing repeating code on each page.
Find following code for the same.
1. To enable page methods
<asp:scriptmanager id="ScriptManager1" runat="server" enablepagemethods="true" />
2. Detect browser close event.
<body onunload="HandleClose()">
3. Call pagemethods to invoke server side event.
<script language="javascript" type="text/javascript">
function HandleClose()
{
alert("Killing the session on the server!!");
PageMethods.AbandonSession();
}
</script>
4. Define your page methods at server side and call your code.
[WebMethod]
public static void AbandonSession()
{
HttpContext.Current.Session.Abandon();
}
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
If you have a button or an imagebutton in the masterpage you can place the next code in you HandleClose() function:
__doPostBack('<%= Button.UniqueID %>','');
or
__doPostBack('<%= ImageButton.UniqueID %>','');
In that case you come in the OnClick event of the button or the imagebutton and there you can handle the Abandon of your Session
In Word you can only store 2 bytes. That is why I use Writer.
|
|
|
|
|
|
Hi,
How to call a ModalPopupExtender when clicked on a node of a treeview.
Thankyou,
YPKI
|
|
|
|
|
What is the problem you are facing to opein the modelpopupextender from the node.
You can open from javascript and from codebehind also.
to show from js, set the behaivorid of the extender and show this like
$find('behaviorId').show();
and from codebehind you can use this
ModalPopupExtender1.Show();
|
|
|
|
|
So I am looking at ASP.NET jobs at the moment and a few of them say they are a digital solutions company or digital agency. Does anyone know what they mean by this? I can't check out the companies cause they are all listed by a recruitment agency.
Also when people talk about commercial development experience, does that mean public facing stuff or just dev experience. I previously worked for a finance company developing inhouse software for our employees, I guess that doesn't count?
I have a good few more resume and ASP.NET job related questions, if this is the wrong forum I would be grateful if someone could point me to a better one.
Thanks in advance,
Colum
|
|
|
|
|
ASP.NET, C#
I dynamically generate few textboxes. When click on a submit, the page refresh itself. It hides a Panel with those textboxes and shows another Panel. In that panel I need to get texts from the textboxes in the previous Panel.
I saved generated textboxes to Session and retrieve them back on postback. But I only get the IDs of textboxes - i CANNOT get textbox.Text properties. Looks like .Text properties were not assigned to these textboxes when I click on submit.
With static textboxes this is very simple. Does anyone have a solution on this?
|
|
|
|
|
AliensXY wrote: I dynamically generate few textboxes.
Where did you created the textboxes ?
You need to create the textbox before Page_Load . Best place to create dynamic control is to Pre_Init().
If you create TextBox control After/On Page_Load, it will not able to maintain the post back data. because, before Page_Load Event, in ASP.NET Page Lifecyle two methods called internally they are LoadPastBackData and LoadViewStateData . So, if you are creating the control after/on page_load it won't be part of Control Tree hierarchy which is generated in Page_Init() event. And PostbackData and ViewStateData loads only for those control which are listed in control hierarchy.
|
|
|
|
|
Thanks for your reply. I am still having the same problems.
For better discussion I added some code now.
Now I generate textboxes in Page_Init method. Some extract from code:
TextBox textBox = new TextBox();
textBox.ID = d.Key.ToString();
textBox.TextMode = TextBoxMode.MultiLine;
textBox.Height = Unit.Pixel(107);
textBox.Width = Unit.Pixel(263);
Then I save them in the session object:
Session.Add("1", textBox);
Session.Add("2", textBox2);
Session.Add("3", textBox3);
After submit I recreate them in Page_Init:
TextBox t = (TextBox)Session["0"];
Response.Write(t.ID);
Response.Write(t.Text);
I sucessfuly get all attributes except Text. If I wrote textBox.Text = "something" I would get this text. But I cannot do that since the user has to type the text into the textboxes.
|
|
|
|
|
I haven't done this for years. but I have a linkbutton inside an itemtemplate in a datagrid see below
<ItemTemplate>
<asp:LinkButton ID="lb_edit" runat="server" CommandName="Edit">Edit</asp:LinkButton>
</ItemTemplate>
What I wish to do is show the editTemplate whenever I click the linkbutton anyone remember how to achieve this?
Any help is appreciated.
ASP all the way
|
|
|
|
|
|
Hi
how can I get image size in Kb in asp.net c#.
I'm providing facility to download image in 800*600 or 1024*768 dimension but along with these links I want to display actual size of image in Kb in both dimensions.
thanks
You get the best out of others when you give the best of yourself.
|
|
|
|
|
Try:
byte[] image;
int length = image.Length;
|
|
|
|
|
I have this very simple form to display message how many checkboxes are selcted but it returns error on the very first line of javascript. could someone please help me. I couldn't figure it out what has gone wrong.
Thanks
<body>
<form id="f1" runat="server">
<input type="checkbox" name="Liked" value="Cool Layout" /> Cool Layout
<input type="checkbox" name="Liked" value="Fun Layout" /> Fun Layout
</form>
</body>
</html>
function CheckLikes()
{
alert(document.f1.Liked[0].checked);-------------->return error
boxes = document.f1.Liked.length;
txt = ""
for (i = 0; i < boxes; i++)
{
alert("hello");
if (document.f1.Liked[i].checked)
{
txt = txt + document.f1.Liked[i].value + " "
}
}
if (txt == "")
{
Message = "No Boxes ticked"
}
else
{
Message = ""
}
alert(Message);
return Message
}
|
|
|
|
|
What error? How are you accessing it?
I find it working fine:
function CheckLikes()
{
alert(document.f1.Liked[0].checked);
boxes = document.f1.Liked.length;
}
<form id="f1" runat="server">
<input type="checkbox" name="Liked" value="Cool Layout" /> Cool Layout
<input type="checkbox" name="Liked" value="Fun Layout" /> Fun Layout
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="javascript:CheckLikes()" />
</form>
|
|
|
|
|
Hi all,
I use the PasswordRecovery control to generate new passwords. I want the new passwords being generated to adhere to a regular expression "^.*(?=.{6,})(?=.*[a-z])(?=.*[A-Z])(?=.*[\d\W]).*$" or the set of rules following 1 small letter,1 capital letter,1 specialcharacter/number. How do I accomplish that?
Regards,
Sahana.
|
|
|
|
|
One way to do so is you can either implement
your own password recovery control.
You can also extend the functionality of password recovery
control by extending it.
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
I am using the asp PasswordRecovery control. Can you tell me how do I extend it?
|
|
|
|
|
Hi All,
I am having an asp:label <asp:Label ID = "lblMessage" runat = "server" Visible = "False"/> and an asp:Button <asp:Button ID = "btnProcess" Text = "Process" runat = "server" onclick="btnProcess_Click" /> at front end.
what I would like to do is when user clicks the button on the web form, then the label displays some message, such as: "the file is loading, please wait". I know i need to use JavaScript to achieve this, but not quite sure how to do it.
I would appreciate someone in here can help me.
Thanks very much.
|
|
|
|
|
AndieDu wrote: <asp:button id="btnProcess" text="Process" runat="server" onclick="btnProcess_Click">
Add OnClientClick="UpdateLabelMessage()" to button control.
Then in Javascript, you need to do something like:
function UpdateLabelMessage()
{
document.getElementById('lblMessage').text = "Message updated";
}
P.S.: label id used in Javascript might change based on the design of your webpage, you can check viewsource to get exact id to use in JS.
|
|
|
|
|
As you made your Label visible false, it wont render on the page and can not be made visible fron javascript.
So better make it like
<asp:label ID="Label1" runat="server" text="Label" style="display:none;"></asp:label>
Now you would be able to show from javascript.
Add onClientClick as Sandeep suggested like
OnClientClick="ShowLabel();"
and your js function would be
function ShowLabel()
{
document.getElementById("<%=Label1.ClientID %>").style.display='';
document.getElementById("<%=Label1.ClientID %>").innerHTML="Updated Text";
}
Let me know for any query
|
|
|
|
|
hi there,
i want to handle browser event in Global.asax.
i can handle it in page(aspx) but problem is that, same code i need to repeate on each page.
so can i define code only once ....?
Thanks in advance
koolprasad2003
Rating always..... WELCOME
Be a good listener...Because Opprtunity knoughts softly...N-Joy
|
|
|
|
|
koolprasad2003 wrote: i want to handle browser event in Global.asax
What do you mean by "Browser Event"?
|
|
|
|