I have 3 update panels on a page. Each of them is set to conditionally update. In each update panel I have a single button control that when clicked will populate the panel with data. Each panel is independent of one another.
Everything is working fine when you manually click each one of the 3 buttons in their respective panel. The issue I am having comes up when I use JavaScript to click the buttons. I have success when executing a single JavaScript call but when I try to click all 3 buttons with JavaScript, things behave sporadically. Depending on where I place the JavaScript calls in my code, different panels work and the others do not.
For example:
__doPostBack('btnBindTeamTicketList', '');
__doPostBack('btnBindPriorityList', '');
__doPostBack('btnSearchTemplate', '');
will show the panel that holds the 'btnSearchTemplate' button, but not the others. Different results occur when I change the sequence around.
Is there a way to click my 3 independent buttons (each in its respective panel) using JavaScript so that each panel will load as if I were clicking on them individually? I am guessing this has to do with the AJAX somehow conflicting with each other or a timing problem. Anyone point me in the right direction?
I am using ASP.NET 3.5/C#
I think you should do one postback. Put a hidden update panel in your page and put a button inside this new update panel. This button should call events
btnBindTeamTicketList_Click(null, null)
btnBindPriorityList_Click(null, null)
btnSearchTemplate_Click(null, null)
and should update the other update panels like upTeamTicketList.Update(). Now try clicking this new button.
Related
So i am using Windows Forms App on visual studio c#. I am developing a game. For that i have given an "INSTRUCTIONS" Form. In that form i want to give the instructions. The game has 4 modes so for each mode i want to give separate instructions. I have used groupBox for providing instructions for each mode. Which means that in the groupBox i have added textBox for instruction. Now for 4 modes i am using 4 groupBox.
Now the question is that how to open groupBox2 then groupBox3 then groupBox4 by clicking on same "NEXT" Button?? Like when the form loads the groupBox1 loads which is for first mode. Now when the user clicks on NEXT button, the groupBox1 gets invisible and the groupBox2 becomes visible which is for second mode. Then again when user clicks on same Next button the groupBox2 gets invisible and groupBox 3 becomes visible.
In the same way for "PREVIOUS" button which will make groupBox3 invisible and groupBox2 visible.
There are a couple reasonable approaches to this.
One would be to keep a variable int step (or similar) in the class data, and inside the button's unified click handler do switch (step).
Another would be to have separate click handlers, and in the first click handler, do NextButton.Click -= Step1NextClicked; NextButton.Click += Step2NextClicked; and similarly in the others.
A variation on the second approach would be for the button click handler to not have any logic of its own, but just call an Action which points to a separate handler function at each stage. Then you can update the Action in a single assignment when changing stages, instead of having to remove the old handler and add the new one.
Yet another approach would be to swap not just the groupbox, but a borderless panel holding both the groupbox and the button. Then you actually have multiple Next buttons that display one at a time in the exact same screen location.
Personally I would use the first option, since it's very efficient. If I had more than a handful of different behaviors, I would probably use the Action approach.
I have an ASP.NET Page where in web.config I have added this setting :
<pages maintainScrollPositionOnPostBack="true">
Now in a aspx page, I have a textbox (txtTop) on top of the form & after user scrolls down (there are lot of controls in between) there is a button.
Inside this button Click event on Server, I have added this code.
txtTop.focus();
I expect that the focus should be on the textbox as well as the scroll position to be pointed towards the textbox.
but it is not happening.
The focus is there on the textbox but it is not getting shown i have to press some key to put the textbox into the scroll position.
These two properties are clashing & I am unable to resolve it.
FYI: There are no update panels..
I created a dirty hack to resolve this.Without setTimeout it was not working neither was document.ready.
$(window).load(function () {
setTimeout(function () {
document.activeElement.scrollIntoView(true);
}, 1);
});
I have an asp.net page with two user controls. Each of which are in separate updatepanel's One user control has three textboxes. I want to update the second updatepanel based on change of text/ focus out in first user control. How can I access both user control's textboxes, and other controls in page and update the updatepanel on change of text ?
updatepanel1
user control1
textbox1
textbox2
textbox3
updatepane2
usercontrol2
label1
Regards,
Asif Hameed
Whoa, UpdatePanels! That takes me back. Triggering UpdatePanels to "postback" asynchronously from the client has always been a bit of a kludge. The common way was to register an AsyncPostBackTrigger with a hidden button's click event and then explicitly call its click event on the client side. However, a solution with a few less layers of indirection is to call the ASP.NET AJAX library's __doPostback() JS function.
Assuming you're using jQuery (which may be far-fetched considering you're still using UpdatePanels!), you can add an event handler to the 'focusout' event of your UserControl1 to trigger the asynchronous postback of your UpdatePanel2. I would recommend putting this JS outside of one of your UpdatePanels.
$('#userControl1').on('focusout', function() {
__doPostback('UpdatePanel2UniqueId', '');
});
I dug up a good article that explains the technique of using __doPostback in a bit more detail.
Easily refresh an UpdatePanel, using JavaScript
I have a page that has 4 tables. Initially when the page is loaded, it shows 1 & 2. Thats working fine. On Post back(When Submit is clicked), it should show 3 & 4. Even thats working fine(code shown here). When the submit is clicked again, it has to call updatePaymentInfo() and redirect. Is there something to write as a condition to call UpdatepaymentInfo() because when submit is clicked, it is taking as an other postback and showing me 3 & 4 again.
protected void imgbtnSubmit_Click(object sender, ImageClickEventArgs e)
{
try
{
if (Page.IsPostBack)
{
trtest.Visible = false;
trCCandBilling.Visible = true;
trtest2.Visible = true;
}
else
{
UpdatePaymentInfo();
Response.Redirect(ApplicationData.URL_MERCHANT_ACCOUNT_HOME, true);
}
}
}
My thought on the easiest way to do this is to have two image submit buttons in the same place. Button A is the one you already have button B is a new one that whose submit handler runs UpdatepaymentInfo and redirects.
Button B starts off invisible while button A is visible. When Button A is clicked in addition to the visibility changes you hide button a and show button B. Then when they click button B the right stuff happens.
Its not that elegant though.
Another solution might be storing values in the page to indicate the current page state that you can then check on button click.
It sounds like you're having trouble managing the current state of your page. You could try:
Having a second submit button. It would be stylistically indistinguishable from the first, and would be hidden/shown accordingly, but would have its own click event.
Placing a hidden form value on the page to track the current "step" of the process.
Breaking the page into two pages, since from the user's perspective it's clearly a two-page process.
My personal favorite, move to MVC :) Though it's understandable if you're stuck in a pre-existing WebForms app and there's just no budget to re-write it.
I guess that imgbtnSubmit_Click handles Click event of the Submit button so this method will be called only during the postback so the condition is incorrect.
I would not use this approach. ASP.NET contains controls which support these requirements. Check MultiView and Wizard. Create separate view with table 1 & 2 and button and another view with table 3 & 4 and button. Button on the first view will switch the view and button on the second view will call the method and redirect.
Another possible way to do this is keep your current set up and add a command argument to the button. By default it has some argument that you check on the first click. Then checking the command argument on the first click you do your showing and change the command argument to be something different. So on the next button click you do the work associated with the second command argument. Thus flipping the work done without having to hide or show a new control.
I have a master template that all the pages on my site use. In the template there is an empty panel. In the code-behind for the page an imagebutton is created in the panel dynamically in my Page_Load section (makes a call to the DB to determine which button should appear via my controller).
On some pages that use this template and have forms on them, pressing the Enter key fires the click event on this imagebutton rather than the submit button in the form. Is there a simple way to prevent the imagebutton click event from firing unless it's clicked by the mouse? I'm thinking a javascript method is a hack, especially since the button doesn't even exist in the master template until the button is dynamically created on Page_Load (this is ugly since I can't simply do <% =btnName.ClientId %> to refer to the button's name in my aspx page).
I tried setting a super-high tabindex for the image button and that did nothing. Also set the button to be the DefaultButton in its panel on the master template but that did not work either. Moreover, I don't want to add a property to all of my pages that use this template (there are hundreds). It would be optimal to find a solution that works globally from my master template.
I'll try to show our example here:
We have a button on the top of each page in our system that lets you star the page as one of your favorites, sort of a server-side bookmark system. When the page loads it looks to see if the page is one of your favorites or not and then shows a gold star if it is, and a gray star if it is not. Clicking the imagebutton of a star toggles the page favorite status.
In my master template (FullMenu.master) I have this panel
<asp:Panel runat="server" ID="pnlFavorite" style="display:inline;"></asp:Panel>
Next there is a class which creates the button and adds it to the panel on the master template:
public void InsertStarButton()
{
CreateStarButton();
pnl.Controls.Add(bright);
}
and
private void CreateStarButton()
{
bright = new ImageButton();
bright.ImageUrl = "~/resources/images/star.png";
bright.Height = new Unit(12, UnitType.Pixel);
bright.ID = "btnStar";
}
What I tried earlier, that didn't work, was in InsertStarButton() I added a line pnl.DefaultButton = "btnStar" but that didn't change anything on the page. Even if I had the cursor blinking inside a text box in the form on the page the star button would fire its click event if the Enter key was pressed.
http://weblogs.asp.net/scottgu/archive/2005/08/04/421647.aspx
Pressing ENTER on a single-line textbox on a form will submit the form. That's how it works.