I have a popup window where i store an a arraylist in sessionvariable, when clicking on closebutton (the X in the right top corner) or the cmd input button in the form i want to remove the sessionvariable containing my arraylist. How can i do this?
The popup window is currently closed by a javascript:
function cmdClose_onclick() {
self.close();
}
Session variables are stored on the server, so you need to inform the server that something happened on the client, and call an appropriate function to remove the session variable.
There are a couple ways you could do this.
You could make an AJAX request to a page, a page method or a custom HTTPHandler. If you write a custom .ashx file, you could simply make a request to it's URL and have it delete the session variable.
Make your page do a postback when you close the window. You can manually trigger postbacks by calling __doPostBack() in javascript, or just executing a button click or form submit.
I'd go with option #1 if you can.
I'd suggest getting the javascript to make an AJAX call to a WebMethod which clears the session variable.
Related
What I want is to open a new popup from the server side, this pop up has a form with three fields, and then return this three fields to the parent page. But I want this fields in the server side, in the VB.NET code. Is this possible?
Is a modal popup window acceptable? If so, you could put the variables in an update panel, and use the server side event of the button that causes a postback on the modal to force the the update panel to update.
Create a form to show as popup
Display it
Perform a POST request onto the parent form to pass the values
or
save input into Session vaariable and read it on popup close
I have a form page that opens a dialog in order to enter new information. I open the dialog in the "standard" jQM way:
Open dialog
What I need to do is pass back some of the values that were entered so that I can update the page with those values. How do I do that?
As an added bonus, I also really need to be able to submit the values. It seems like jQuery Mobile is setup close the page on any link click. This is an ASP.NET application, and so I need for the page to last long enough to hit the Button_Click() event in the code behind.
Here's the pieces you need:
Html in the dialog:
Cancel
Submit
In pagecreate:
$("#btnSave", pagediv).live('click', function () {
var s = page.Model;
s.serverName = $("#txtName", pagediv).val();
s.Save(function () {
$('.ui-dialog').dialog('close');
});
});
s.Save is a function that writes to the datastore, updates a global model object that is accessible to all pages, then calls the callback function.
In the pageshow handler for the parent page, update the controls from the model. You can't update the parent page directly from the dialog as the parent page may not exist at that point - if data-dom-cache isn't set, it will be removed as soon as the dialog is displayed and will not be recreated until you call close.
I'm using telerik radgrid control with following layout:
I'm curious if anybody can provide general guidance in what approach I should take to reliably update user control that initiated popup window action?
On radWindow OnClientClose event you can write up javascript code to reload the user control which initiated the action.
I had a somewhat similar requirement sometime ago, where I needed to rebind the grid after closing the radWindow and used the onclientclose
function RefreshGrid() {
var masterTable = $find("<%= GRIDNAME.ClientID %>").get_masterTableView();
masterTable.rebind();
}
In any case, I suggest you to look into the javascript api on how to update the user control(depends on what you want to update on the user control).
So here is how I've solve the problem:
I created "hidden" button on each tab's user control that needs to be updated and passed in button client id when opening popup. this button client id is stored as java script variable and when user close modal rad window I execute code that simulate hidden button click:
$find(myStoredButtonClientIdJSVariable).click();
That in turns execute proper user control server side code and my grid is properly refreshed.
Hope somebody might have some benefits reading this.
There is one column of textbox in my item template. When I run the page and click on the textbox I want an event to fire. How can I make this happen?
What do you want to do when someone clicks? Odds are it's something you'd be best off processing on the client in JavaScript, possibly using jQuery. JavaScript will happily handle a "textbox" click event, although by the time your textbox hits the browser it's been rendered as an <input type="text">.
Think of ASP.Net as being a tool that generates and manipulates HTML, and sends it to/from the browser. ASP.Net events are the result of the browser posting the entire page back to the server, the server doing something to it, and the server sending the whole page back. There's obviously times when that is what you'd want, and times when it's not, I suspect this will be the latter, unless you're doing something data related.
To show a div on textbox click, I would use the jQuery Show() and Hide() methods. Create your content in ASP.net, and use 1 jQuery function to hide the div when the page loads (on browser, not server), and another to show them. Have a look at these - http://api.jquery.com/show/ and http://api.jquery.com/hide/ . The examples on that page will translate to what you're after; don't let the ASP.Net thing distract you, by the time your page is on the browser it's in HTML.
LinkButtons are giving me headaches. I thought, foolishly, that they allowed you to create programmatic links. Obviously this is not the case (by design), as they have behave nothing like normal links - you can't see your address when you hover over them, you can't open them in a new tab, etc.
Is there an alternative in .NET that actually lets you programmatically create a true HTML link? The ability to open multiple items in tabs is sort of a requirement. I've looked into styling a Button to look like a link, but it still behaves like a button, so this won't work either. Any ideas?
EDIT: Sorry, forgot: can't use HyperLink, as I need the ability to send CommandArguments, set OnClick events, etc. It needs to function as a button still.
The HyperLink control.
Set the href using the NavigateUrl property, and tagets (for new windows/tabs) can be set using the Target property
Edit to respond to question edit
I'm not really sure what you're after - your question is asking for a control that "functions like a normal link", so that clicking on it can open in a new window/tab, but your edit says you want to be submitting CommandArguments and using the OnClick event - so not a normal link.
The problem you've got here is that the PostBack processing of command arguments and OnClick events happens at the server, but the "open in a new window" happens on the client (using the "target" attribute of the anchor tag, or possibly with JavaScript) - these two don't really mix all that well.
A couple of options spring to mind:
Use a LinkButton, and if you handle a PostBack, output some JavaScript to open the new page in a new window.
Use a HyperLink control with a target and set the "CommandArguments" as a querystring element to the link - you can then process that on the catching page that opens in the new tab.
You can also cause JavaScript to fire onClick using the Attributes collection:
// Create a hyperlink
HyperLink link = new HyperLink();
link.NavigateUrl = "/somepage.aspx?arg=First";
link.Target = "_blank"; // Open in a new window
// Add a client side onClick event calling someMethod function with a reference
// to the link, and making sure the link processing stops.
link.Attributes.Add("onClick", "someMethod(this);return false");
You mean HyperLink?
Of course you could always use the a tag in HTML.
EDIT: When you hover over a link, the browser displays the target. When you hover over a LinkButton, the browser displays the javascript call that will execute the function server side. I'd say the best you can do is display the target page in the ToolTip, since I think it would be pretty tough to display it in the browser.
If you use a LinkButton you will be able to set the command arguments and the onclick method in your code behind. By doing so, you will no longer be able to open the link in a new window as you have found out.
One of the reasons that you cannot open a LinkButton in a new window is because it is doing a postback to the same page.
I think you either have to use a HyperLink control and pass the command argument as a query string parameter or use a LinkButton control and loose the open in a new tab functionality.
If you pass the argument as a query string parameter, then you can check for that param in page load and still call your onclick function which you were going to use for your LinkButton.
Hope this is clear and it helps you.