I'm using Ajax Update panel, now i'm trying to transfer from one aspx page to another apsx page by using server.transfer , but it is giving error.
I have tried
Server.Transfer("User.aspx");
Add this to your update panel if you don't have it.
<Triggers>
<asp:PostBackTrigger ControlID="btnYourButtonId"/>
</Triggers>
Remember to keep it asp:PostBackTrigger instead of asp:AsyncPostBackTrigger. Latter doesn't work with server.transfer.
Related
at my webforms.app on .net 4.0 after call _doPostBack via
aspx code
<%= GetPostBackReference() %>;
on code behind
protected string GetPostBackReference()
{
return Page.ClientScript.GetPostBackEventReference(ReloadThePanel,"null");
}
transformed to
__doPostBack('ctl00$cntMain$ReloadThePanel','null');
in form
<!-- update panel -->
<asp:UpdatePanel ID="updPanelSave" ClientIDMode="Static" runat="server">
<ContentTemplate></ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ReloadThePanel" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<!-- hidden button for update panel -->
<asp:LinkButton ID="ReloadThePanel" runat="server" style="display:none;" />
after first ajax postback is all ok, after another one ajax postback on same page it throw js exception
form.__EVENTTARGET.value undeffined
in (Scriptresource.axd ... dynamic code)
_doPostBack: function PageRequestManager$_doPostBack(eventTarget, eventArgument) ....
form.__EVENTTARGET.value = eventTarget;
form.__EVENTARGUMENT.value = eventArgument;
this._onFormSubmit();
what i do wrong ? Its maybee same isue with http://www.hanselman.com/blog/IE10AndIE11AndWindows81AndDoPostBack.aspx
problém is only on ie 11,8 usw.. Chrome and FF works well
Thanx
Easiest thing to do is upgrade to 4.5.1 - it may be that issue you mention and that'd solve it.
Seems strange that it happens AFTER and initial postback though (and doesn't tie in with the issue above).
Personally I don't see much point in creating the postback reference by using a hidden button (and suspect that's where it's getting itself confused). You have blank content template here, but there is probably something contained within in the real code, make sure you don't have any unmatched div tags as that would push the button into the panel and you'd lose reference to it.
I'm guessing that you must be calling the postback from javascript (otherwise why use a hidden button), so why not just use: . You might want to populate the id programatically (in aspx : ', '');"> )
I know it seems nasty including direct references to __dopostback - but the day M$ change that is the day that 90% of webforms websites will go down anyway, so it's pretty unlikely.
i am tried like this, i take an button control which display is none:-
<div style="display:none">
<asp:Button ID="loginbtn" runat="server" OnClick="loginbtn_Click" />
</div>
Then I call the click event of the button through jquery:-
$("input[id$=loginbtn]").click();
in Server side I call button event:-
protected void loginbtn_Click(object sender, EventArgs e)
{
}
Its working fine,But,it reload the page, I need to Stop it , Please give me some solution how to call the server side method from client side in DNN
In this case (I'm assuming you are developing a module for DotNetNuke); The easiest way is to check "Supports Partial Rendering" in your module control. Then it will be wrapped by an Update Panel.
Host -> Extensions -> Edit your module -> Module Definitions -> Module Controls -> Edit your module control -> Check Supports Partial Rendering
However, if a control already contains JavaScript for dynamic behaviors, wrapping the control in an Update Panel has the potential to break the control's functionality.
There are a couple of ways to do this, say, using an UpdatePanel or changing your mechanism to use AJAX directly with WebMethod methods; let me introduce the easiest example for your case before you consider more. Wrap your content in an update panel, as such:
<asp:UpdatePanel runat="server">
<ContentTemplate>
<!-- stuff to reload here -->
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="loginbtn" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
So, then the other option is to use jQuery's ajax or equivalents (such as post) to submit your data programatically (rather than somewhat macroing the UI - which might not even work in some browsers such as versions of IE). The AJAX call can return data and you can populate your pieces in place as required.
I need help with something, it might be a bit complicated. I call a WebMethod that does somethings from inside a js file. One of the things it does, is that it calls some functions that are located in a class within the app_code.
In that class in app_code I get a GridView Control that is on my page and I need to update it, so I do this:
ActiveGridView.DataSource = (ActiveDataTable).DefaultView;
ActiveGridView.DataBind();
The above works fine when I call the functions in app_code from a regular function, but doesn't update the grid when I call it within the WebMethod.
Any ideas how to solve this problem?
Please note that I CAN'T have the WebMethod return the data and then on client side to update the grid.
Edited
Actually I am using a updatePanel, my aspx code looks like this:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="MappedDataGrid" runat="server" CssClass="pipesTbl">
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnRemove" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
And again this works fine when I call the fill grid from an event on the page, but then when I call it after a webMethods calls the class in app_code that is spouse to fill the grid, it doesn't get refilled.
Edited again
I think the problem is with this line:
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnRemove" EventName="Click" />
</Triggers>
I tried changing it to this:
<Triggers>
<asp:AsyncPostBackTrigger ControlID="MappedDataGrid" EventName="DataBinding" />
</Triggers>
But didn't work, I am probably missing something, and since this is all new to me, I didn't know what to do.
What should I be doing now in order to make it work as you said?
If you call a method which manipulates a ASP.NET page out of the lifecycle of that page, you won't view the result. If you want to bind data to a ASP.NET control, it needs to be in the lifecycle of the page, and if you call the method from javascript throught a webmethod, that method will be executed out of the lifecycle.
Try to fill the datagrid with AJAX embedding it in a UpdatePanel.
When you call a WebMethod you are not actually loading the page and running through the page lifecycle. Even though your method is part of your page codebehind class, when you call it in this way your controls on the page are not going to be available. It's just a shortcut for making a web service out of a method in your page class.
Based on what you say you want to do, you may want to look at using an UpdatePanel. With them, it IS actually doing a full postback to the page and you can change whatever is necessary with your page controls.
Update
The point with the UpdatePanel is that you won't use your WebMethod anymore. You will just click a normal button that is a trigger for the update panel, and you will update your grid like normal in the code behind (handle the click event of the button and call your code to bind the grid). Since only the grid is in the panel, only it will get refreshed on the screen.
I have an UpdatePanel with some checkboxes in it. I check them, and hit my Save button, but that causes the UpdatePanel to postback (refresh) and sets them all back to blank. The re-drawing method runs before the button code.
What is the correct way to have an UpdatePanel with checkboxes in that you can manipulate?
Example of code:
<asp:UpdatePanel runat="server" UpdateMode="Conditional" ID="updatePanel1">
<ContentTemplate>
<asp:CheckBox runat="server" ID="myCheckBox" Caption="CheckBox"/>
<asp:Button runat="server" ID="saveButton"
Caption="Save" OnClick="SaveButtonClick"/>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="saveButton" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
Make sure that:
UpdateMode of UpdatePanel is Conditional
SaveButton contained in Triggers-section as ControlID of AsyncPostBackTrigger
Your code behind should look like:
if(!page.ispostback)
{
re-drawing();
}
As when you hit Save button your re-drawing() method is called and it again refreshes your checkboxes. Asynchronous postback behaves and hit to page method the same as full postback, but refreshes the values in any updatepanels.
Also check this URL
http://ajax.net-tutorials.com/controls/updatepanel-control/
Make sure the Save button is inside the Update Panel, for a start, and if not, that is designated as a Trigger for the Update Panel, in the <Triggers> section of the Update Panel.
<asp:UpdatePanel ID="MyControlPanel" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="SaveButton" />
</Triggers>
<ContentTemplate> ...
Can you show some code for your UpdatePanel?
If you use server controls to render checkboxes you should add EnableViewState="true" attribute to these controls and update panel.
If you have checkboxes that are not server controls, then remove them from update panel, include only server controls inside. This leads to keeping several updates panel on a page that's usually not a big issue.
Add a ScriptManager object to your page if you do not have one. Set EnablePartialRendering="true". Put your UpdatePanel anywhere else on the page and place the content you want ajaxified within a tag within your UpdatePanel.
How can update a input hidden inside an UpdatePanel on an AsyncPostBack?
The user click a button outside the panel. The method associated with click event update the value of the input (it has runat="server" property).
I can't update the value of this input.
I need to store a value to use in the following postback. Maybe I can use session to store this value.
Any advice?
Thank you!
Because its a postback, you might have to perform a check in the post back event and perform the update. If not, you might have to override an earlier event. See http://msdn.microsoft.com/en-us/library/dct97kc3.aspx
If you are needing to have the update panel (and its contents) updated based on the user clicking on a button which is not in the update panel, add a section to the update panel like the following:
<asp:Button ID="btnOK" runat="server"/>
<asp:UpdatePanel ID="pnlMyPanel" runat="server">
<ContentTemplate>
<!-- Content to get updated -->
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnOK" />
</Triggers>
</asp:UpdatePanel>
The triggers section in the above example tells the update panel to update if the button is clicked.
You might want to try an <asp:HiddenField> rather than an <input type='hidden' runat='server'>. I think the asp.net version is more post-back aware.
No way. The only way to update an input is to do a complete post. It's better to use the object Session.