StartupScript not triggered - c#

Lets me explain the situation.
I have a gridview, when I hit an add button I show a popup window and let the user enter the info. When the info is completed, the user clicks OK and a client side comprobation is made and an e.processOnServer = isValid; with a true in there, so the server event runs (btnSubmitConfig_Click), and at the end of this function in code behind I need to insert this startup script to make an callback in the gridview to see that is populated, while the popup remains open with a message saying submit successful
My startup script is:
ScriptManager.RegisterStartupScript(this, GetType(), "Javascript", "aspxgridEditLog.PerformCallback(); ", true);
And is not fired.
Any guesses please?
Thanks

I found the problem, I had to insert this script in the Parent.Page, instead of this because it was trying to find the gridview in the popup, so it wasn't finding it.
Now works:
ScriptManager.RegisterStartupScript(this.Parent.Page, Parent.Page.GetType(), "Javascript", "aspxgridEditLog.PerformCallback(); ", true);
Thanks for the guesses, you helped me think about what was the problem.

Related

how to stop Double Click on my aspx page on server side without Javascript

I am facing automatic multiple clicks on my Button in all pages of my website. I put JavaScript to disable the button on click. It's working but on the server side it's not working. I want to stop double click on server side without JavaScript.
There is nothing to be easily done without JavaScript included. But let's assume there is no way to use JavaScript for a reason.
You will need to trace the server side calls, for example:
You can have a seconds life time variable (session variable) and each time you call the server you set it to true, and if you found it true on the next call this means it is a second click.
Try adding the following code to the button
btnSubmit.Attributes.Add("onclick", " this.disabled = true; " + ClientScript.GetPostBackEventReference(btnSubmit, null) + ";");
Please let me know if this solved your problem
In your click event you can just add in
Btnsubmit.enabled=false

How to implement an if else condition in the code behind for ImageButton OnClick

I am working on my website design and have already implemented a simple slideshow consisting of image buttons that would redirect users to different pages when they click on them. However the issue that I've noticed is that all of the images redirect users to the same page and I realized it was due to all the Images in the slideshow inheriting the method Response.Redirect("url")...then I tried to use an if else condition for example
if(ImageButton3.ImageUrl=="/Images/Homepage_Button.PNG")
{
Response.Redirect("Homepage.aspx");
}
However I have noticed that this method does not work. Do you guys have any suggestions, huge thanks in advance!!!
I would suggest you use a data-url attribute on your image buttons. When you post back you can get the url off the ((ImageButton)sender).Attributes("data-url") and redirect to that url.
Another suggestion, if you aren't doing anything else in the event handler, you could simply use links around images.
Did you try to debug this code? To see if it reaches the URL you specified?
You can do that by clicking on "Start with Debugging" in Visual Studio.
Another good bug ugly debugging method is to add an alert (MessageBox) inside the if sequence and see if it gets there. For example:
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", ("The URL is " + ImageButton3.ImageUrl));
if(ImageButton3.ImageUrl=="/Images/Homepage_Button.PNG")
{
Response.Redirect("Homepage.aspx");
}
Edit: After seeing your comment, I suggest accessing this image like that (notice the #):
if(ImageButton3.ImageUrl=="#Images\Homepage_Button.PNG")
{
Response.Redirect("Homepage.aspx");
}

Auto Complete Textbox Enter to activate Search

I have a Ajax auto complete extender attached to TextBox control. When the user starts typing the suggestive options are displayed in the divsion underneath. Getting the suggestion from a webservice call. On OnClientItemSelected="GetCode" I am using the below JavaScript to get the selected suggestion text into the search box.
Now I want the ENTER click to activate the search.
If the user selects from the suggestions he is getting and clicks the enter. It works fine. It activates the search. This is the code I am using.
function GetCode(source, eventArgs) {
var txtValue = document.getElementById('<%=txtAutoComplete.ClientID%>');
txtValue.value = eventArgs._value;
//$('#<%= txtAutoComplete.ClientID %>').val(eventArgs._value);
$('#<%= ImageButton1.ClientID %>').click();
}
But The problem is if the user doesnt select from the suggestion and types some text and clicks the enter key Doesnot activate search. Yes I know that It doesnot call the GetCode Function.
I am not getting how to do this. Anyone Please help me..
I am want something exactly like in www.laterooms.co.uk
You have to set a default button for either the form or the text field.

Selenium-RC Unable to handle Confirmation box

I am testing a web app where i delete an item from a list. Upon clicking on delete, the app asks for confirmation. Selenium IDE detects it as a confirmation box. When I run the code thro' the RC (C#), it even catches the confirmation-box, executes the click of delete button on that confirmation box, but, the confirmation box is never visible on the screen. Further, it only clicks on the delete button; the item doesn't get deleted. I tried it manually, works fine.
Please help, I'm new to Selenium and tried to find the answers at multiple forums without any success.
Here's the code:
string confirmation;
for (int second = 0;; second++) {
if (second >= 60) Assert.Fail("timeout");
try
{
confirmation=selenium.GetConfirmation();
if ((confirmation == " Delete confirmation message")) break;
}
catch (Exception e)
{
PrintLog("Error while waiting for confirmation. Error: "+e.Message);
}
Thread.Sleep(1000);
}
try
{
Assert.IsTrue(confirmation == "Delete confirmation message");
}
catch (AssertionException e)
{
PrintLog(e.Message);
}
selenium.FireEvent("//a[#id='btnOkConfirm']","click");
After the last statement, the selected item must get deleted and page should refresh, but, nothing happens. All I can see is "Javascript:;" written in the status bar of the firefox window. I guess its problematic to get javascript hrefs working in selenium-rc.
Thanks,
Vamyip
There are a number of commands to deal with JavaScript confirmations. Selenium will by default choose 'OK' at a confirmation, unless you send the chooseCancelOnNextConfirmation command. In order to consume the confirmation you will need to use the getConfirmation command.
Selenium reference for above commands:
http://release.seleniumhq.org/selenium-core/1.0/reference.html#storeConfirmation
http://release.seleniumhq.org/selenium-core/1.0/reference.html#chooseCancelOnNextConfirmation
http://release.seleniumhq.org/selenium-core/1.0/reference.html#chooseOkOnNextConfirmation
Additionally, if your click command is not showing the JavaScript confirmation you might find that the appropriate event is not being fired. You could try using the mouseDown and mouseUpcommands, or the fireEvent command.
Lately, I've discovered that this behavior is occurring due to the architecture of selenium(more precisely, its javascript based core). when I do the test manually, keeping the selenium IDE open, this behavior is replicated. So, I think there's no immediate solution to this problem right now. Will post here if I find a workaround.
Thanks to Dave for replying.
Update: The development team informed me that a javascript function is not being called with selenium IDE running alongside. This indeed is a problem with Selenium's Javascript core.
Thanks to everybody who took time to respond to this question.
Regards,
Vamyip

Open new window from code-behind

I need to open a new window from code-behind on post-back if a specific radio button is selected.
Is there any way to do this?
Thank you.
You can use RegisterStartupScript to send a window.open script to run once the page has loaded.
However, this will cause the majority of popup blockers to get in your way.
I think this should work ;-)
Add some javascript to your radio button to open a new blank window before you post back. This makes it so popup blockers won't block your popup, since it's opened in response to a users click. See this link for how to do this part.
Then, allow the postback to happen as normal and on page load, register a startup script to tell your already existing window to go to a new url.
String script = "window.open('popupPage.aspx', 'myPopup')";
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "someId", script, true);
Note that in javascript, when you call
window.open(url, 'myPopup')
if a window already exists with that name it'll return it instead of creating a new window... So your popup won't get blocked!
You will need to run javascript on postback
Simple sample of RegisterStartupScript:
RegisterStartupScript("id1", "<script type=\"text/javascript\">alert(\"I'm from JavaScript.\");</script>");
New windows can be very sketchy, depending on the content that you need to present you might consider using an in window pop-in if you will. You will avoid pop-up blockers that way. If you can give more details we can give better answers.

Categories