Showing posts with label button. Show all posts
Showing posts with label button. Show all posts

Monday, March 26, 2012

Instant GridView Refresh on Update Button Click

I have an application that allows for the updating of data in an Oracle table. I am using Atlas, with ObjectDataSources.

There is a quicklist gridview displaying the data, the user picks the record and it displays some options for updating the record in a seperate form on the page.

Upon clicking the update button the record is updated and a Verify changes button is displayed. When the user clicks the Verify changes button the page will display the correct update.

I have found no other way to to display the change on the Update button click.

Is there a way to instantly show the update with only one click of a button. I want the gridview to rebind and display the new update with the update button click. Why does it take two clicks to show the update?

are you using Gridview1.Databind() when you click update?

That forces an update no matter what.

Saturday, March 24, 2012

Invoke an exe file on server side

I created a page with a button. The user presses this button and it is supposed to invoke an exe file that works on the server side. I tried the following code behind:

Label2.Text ="The bot began it's work. Pleas wait..."Dim startInfo As System.Diagnostics.ProcessStartInfoDim pStart As New System.Diagnostics.ProcessstartInfo = New System.Diagnostics.ProcessStartInfo("http://.../files/BotScript1.exe")pStart.StartInfo = startInfopStart.Start()pStart.WaitForExit()Label2.Text = "The bot has finished it's work"

My problem is that this doesn't work on the server side: Pressing the button asks the user if he wants to open the file. I want this file to work on the server.

If this can't be done for security reasons (I don't see why not - this file has nothing to do with the user, but is part of the server script), I would like to use the source code of this exe file and run it on the server. The problem doing it this way is that the script is in c# and my pages are in VB.NET.

Thanks
Yoni

If the .exe is on your web server, try using Server.MapPath in the ProcessStartInfo() to get the actual file location, instead of the HTTP (virtual) location.


doyleits:

If the .exe is on your web server, try using Server.MapPath in the ProcessStartInfo() to get the actual file location, instead of the HTTP (virtual) location.

I tried that, and the exe runs, but as a diff problem came up, I decided to put the source code in my code behind page. I now face a new problem:

I have created a listbox inside an update panel, but when I use the code behind to add items to the listbox (in order to notify the user whats going on) - they added items don't appear until the server is done with the code. How can I get the listbox to refresh itself every time I add/remove/edit items from it?

Thanks,
Yoni


Put the ListBox inside UpdatePanel. Also set the UpdateMode property toConditional

When items will be added/deleted call UpdatePanel1.Update()

http://www.asp.net/ajax/documentation/live/mref/M_System_Web_UI_UpdatePanel_Update.aspx


chetan.sarode:

Put the ListBox inside UpdatePanel. Also set the UpdateMode property toConditional

When items will be added/deleted call UpdatePanel1.Update()

http://www.asp.net/ajax/documentation/live/mref/M_System_Web_UI_UpdatePanel_Update.aspx

I did as you said: I added a UpdateMode="Conditional" property to the Update Panel and used the Update() function after every change I did to the list - but still nothing. Any ideas?

Thanks
Yoni


Hi Yoni,

I recommend copying those source code into a class library. And reference the assembly in your web application. It's better than changing security settings.

After the class library has been compiled into an assembly, it can be used regardless of what language it's written in.


Sorry, I didn't notice that you've solved the running exe issue.

yonidebest:

I tried that, and the exe runs, but as a diff problem came up, I decided to put the source code in my code behind page. I now face a new problem:

I have created a listbox inside an update panel, but when I use the code behind to add items to the listbox (in order to notify the user whats going on) - they added items don't appear until the server is done with the code. How can I get the listbox to refresh itself every time I add/remove/edit items from it?

Thanks,
Yoni

I think you can add a timer on the page to refresh the page at a specific interval.

Invoke Javascript method after partial postback ?

Howdy All,

This might be an easy one but I don't seem to be able to figure it out.

Basically I have an update panel which contains a button that causes the partial postback. After the postback I'd like it to call a Javascript method.

I tried looking to set it on an atlas object and I even tried some hacks like putting a literal control in the Update Panel and setting the text to <script language=""Javascript"">testFunction();</script>" but still no cigar.

Any help would be greatly appreciated.

Try registering your script on the server-side, during the partial post. The script you register will be executed when the response is received from the partial postback.

Page.ClientScript.RegisterStartupScript

-Tony


in my callback function i havestring js = "alert('s');"; Page.ClientScript.RegisterStartupScript(GetType(), "key", js);It doesn't fire

casaubon:

in my callback function i have string js = "alert('s');"; Page.ClientScript.RegisterStartupScript(GetType(), "key", js); It doesn't fire

You need to wrap your js in <script type="text/javascript"> </script>, or use the overloaded RegisterStartupScript specifying "true" for the last parameter.

Hope this helps,

-Tony

invoke ModalPopUp from GridView button

I've got a ModelPopUp that works just fine from a LinkButton.

Now I need to launch the popup from a button in a GridView column/cell. Is there a way to specify that button in TargetControlID property - or is there another way I can programmatically invoke the modalpopup?

I Have a similar problem. I need to launch the popup from a treeview node, with the added hassle that I also need the modal popup to know the Id of the tree node that poped it up!

If I find a solution, I will post here for you.


Well, I can't say this is real elegant, but the way I do it is to put a button on the form, outside of the GridView and set its class so it's not visible (Make sure you use a style and not God forbid, the control's visible property!) Use this button's ID as your TargetControlID.

Attach a client side script to the button in your GridView that is supposed to launch the popup. In the script, call the fake button's click event.

So the code will be something like this:

<asp:ButtonID="ProxyButton"runat="server"CssClass="hidden"/>

<atlasToolkit:ModalPopupPropertiesTargetControlID="ProxyButton" .../>

In the GridView:

<asp:ImageButtonID="..."runat="server"OnClientClick="fakeClick()" .../>

The script:

function fakeClick() {

$('ProxyButton').click();

}

Hope it helps.

Kathy


Thanks Kathy - this does invoke the modal dialog just fine, but it generates two problems I'm hoping you can help with. The first is that the ProxyButton postback clears the modal just as soon as it's shown. Second, I don't know how to access the commandargument from the script - this contains the ID of which grid row the button was clicked on.

Any help?


As for the first problem, I don't think that the proxy button's postback is causing the refresh. It's a fake click after all. It's most probably the button in the GridView (or imagebutton or linkbutton or whatever it is). I don't know your exact scenario, but you may want to consider one of the following options:

1- Use an html control in your grid to invoke the click event of the fake button. Something like a simple div or img with its onclick event set to fakeClick(). As you know these won't cause a postback.

2- Enclose your GridView in an atlas:UpdatePanel. This will keep the button from posting back, too.

As for the second one, if you populate your GridView in the code (as opposed to automatically), you can bind the click event there and pass whatever argument you want, in there, too. Like say you want to launch the popup upon clicking an imagebutton control called Modify, in the grid, and you want to pass the ID of the record as the argument (assuming you got the value in sID and assuming you write VB code):

Dim ibModifyAs ImageButton

ibModify =CType(e.Row.FindControl("Modify"), ImageButton)

ib.Attributes.Add("onClick","fakeClick('" & sID &"')")

If you populate the grid automatically, there is a syntax for doing this in the aspx code itself, but I'm not sure of it. So the good news is that tt can be done and the bad news is that you have to do a little more searching on it. (I will post it if I remember it!)

Now you have to alter the fakeClick script to accept an input argument. You can pass it from there and do anything you want to do. Just to give you a heads up, if you are trying to populate your popup control dynamically, I hope you just have a little html code that needs to go in there. If you want to populate it dynamically, with server controls and all, you're in for a ride :)

Hope this helps.

Kathy


Hi everyone,

You might be interested in checking outhttp://forums.asp.net/thread/1404770.aspx which provides an example of invokingModalPopup from the server in response to aCommand event.

Thanks,
Ted

Are you sure that your javascript will work!?

function fakeClick() {

$('ProxyButton').click();

}

I think NO, becauseProxyButton is asp:Button

and $('ProxyButton') will be NULL, /$('ProxyButton')=document.getElementById('ProxyButton'), butProxyButton should be HTML element

What you think?


Hi StoyanPetrov,

The JavaScript should be fine - the asp:Button will render an HTML DOM element with the same name which then gets picked up by $.

Thanks,
Ted

Hi,

I've been trying to do the same thing and as mentioned above. The page does do an AJAX postback which will cause all the controls to be reset and hence the popup to disappear( you can test this by putting a breakpoint on the Page_Load function).

I found a fairly clumsy way around this. you basically have to do the following.

i) add an event handler for OnRowCreated for the gridview and bind an event handler to the button. In this case called ButtonX

protected void RowAdding(object o,GridViewRowEventArgs e)
{
ImageButton ib=(ImageButton)e.Row.FindControl("ButtonX");
if (ib != null)
{

ib.Click += new ImageClickEventHandler(ib_Click);

}

}

ii) in that event handler store the popup state in the session and refresh the updatepanel

void ib_Click(object sender, ImageClickEventArgs e)
{
Session["ShowPane"] = "1";
UpdatePanel1.Update();

}

iii) override the render and show the panel based on the session

protected override void Render(HtmlTextWriter writer)
{

if (Session["ShowPane"] != null)
{
if (Session["ShowPane"].ToString() == "1")
{
ModalPopupExtender1.Show();
}
}


base.Render(writer);
}

I think the smart thing to do would be to stop the postback in the firstplace, does anyone know how to do this?

Invoking ModalPopupExtender causes Submit button to not postback

I have a simple webform that contains a textbox and a required field validator. The page also has a modal popup extender tied to a button as well as two other buttons for saving the page's input and canceling the pages changes. The cancel button has causesvalidation="false".

I run the web application and on the page in question click the button that causes modal popup to show and then hide the modal popup. The textbox on the page does not have any text and so the validator shows the invalid message. When I click the 'Cancel' button the first time the page does nothing. If I click it again, the server side event handler is fired. Given that causesvalidation is set to false I expected the server event handler to fire on both occasions.

Here is the sample code that displays the said behavior -

<asp:ScriptManager ID="scriptManager1" runat="server" />
<div>
<asp:Label ID="label1" Text="Label1" runat="server" />
<asp:TextBox ID="textbox1" runat="server" />
<asp:RequiredFieldValidator ID="textRequiredFieldValidator" ControlToValidate="textbox1"
Text="*" runat="server" />
<br />
<asp:Button ID="popperUpperButton" Text="Show Popup" runat="server" />
<asp:UpdatePanel ID="pageUpdatePanel" UpdateMode="Always" runat="server">
<ContentTemplate>
<asp:Button ID="submitButton" Text="Send" OnClick="SubmitButton_Click" runat="server" />
<asp:Button ID="pageCancelButton" Text="Cancel" CausesValidation="false" OnClick="PageCancelButton_Click"
runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
<br />
<asp:Label ID="statusLabel" runat="server" />
<act:ModalPopupExtender PopupControlID="modalPopupPanel" TargetControlID="popperUpperButton"
OkControlID="okButton" CancelControlID="leavePopupLinkButton" runat="server" />
</div>
<asp:Panel ID="modalPopupPanel" runat="server">
Just some text that is shown in the popup window.
<asp:Button ID="okButton" Text="OK" runat="server" />
<asp:LinkButton ID="leavePopupLinkButton" Text="Leave Popup" runat="server">
</asp:LinkButton>
</asp:Panel>

Server event handler code -

protected void Page_Load(object sender, EventArgs e)
{

}

protected void SubmitButton_Click(object sender, EventArgs e)
{
this.statusLabel.Text += "submit clicked...";
}

protected void PageCancelButton_Click(object sender, EventArgs e)
{
this.statusLabel.Text += "cancel clicked...";
}

Has anyone else seen this behavior and is there a known fix? I am seeing it consistently on the application I am building.

Thanks in advance,

Ruwan

Why are the submitButton and cancelButtons in an UpdatePanel but the textbox is not? Could you try to get the page working without the updatepanel first? I am not sure this issue has anything to do with the modalpopup being on the page.


Thanks for the response. I have tried the above with and without the updatepanel and see the same result. My reason for suspecting some coupling with the ModalPopupExtender is that the issue does not show up till the ModalPopupExtender is placed on the page.

The updated ASPX page reads -

<asp:ScriptManager ID="scriptManager1" runat="server" />
<div>
<asp:Label ID="label1" Text="Label1" runat="server" />
<asp:TextBox ID="textbox1" runat="server" />
<asp:RequiredFieldValidator ID="textRequiredFieldValidator" ControlToValidate="textbox1"
Text="*" runat="server" />
<br />
<asp:Button ID="popperUpperButton" Text="Show Popup" runat="server" />
<asp:Button ID="submitButton" Text="Send" OnClick="SubmitButton_Click" runat="server" />
<asp:Button ID="pageCancelButton" Text="Cancel" CausesValidation="false" OnClick="PageCancelButton_Click"
runat="server" />
<br />
<asp:Label ID="statusLabel" runat="server" />
</div>
<asp:Panel ID="modalPopupPanel" runat="server">
Just some text that is shown in the popup window.
<asp:Button ID="okButton" Text="OK" runat="server" />
<asp:LinkButton ID="leavePopupLinkButton" Text="Leave Popup" runat="server">
</asp:LinkButton>
</asp:Panel

Thanks,


have you tried adding a validationgroup attribute to the validator and the submit button. adding a attribute like validatorgroup="vg1" to both should cause all other control to ignore the validation except what is part of the group. This may help.


also, I will agree with kirtid, the use of the update panel may be part of the problem. Your update panel only wraps the 2 buttons, so clicking 1 will fire but you will not be able to see the results. if the label is NOT in the update panel. it will not be updated. Try moving the label into the update panel and see if it gets written to. also move the textbox and validator into the UP as well so they can be fired and accessed. I just ran that code with all of them inside the update panel, and it worked for me.

-Alan


Alan,

The ValidationGroup suggestion has provided a work-around for the test application, which now works fine. I will merge the solution in the product that first brought up the issue.

Thanks for the help!