How to display a Yes/No style message box in web part, and get client's choice? - asp.net

I want to show a message box when users trying to do any major operations in my web part. If user choince [Yes], then continue to do sometiing ...[No] for nothing.
How can i implements this function in my web part , Sharepoint 2007 ??
pls help me ~~
thx

If you're using an ASP.Net control like a Button, you can add the following attribute to give the user a JavaScript popup before the postback actually happens:
<asp:Button runat="server" ID="Button1" OnClick="Button1_Click" OnClientClick="return confirm('Are you sure you want to do this?');" />
You can also set this property on the button object in your code:
Button1.OnClientClick = "return confirm('Are you sure you want to do this?');";

Related

Disable control while post back is happening

I'm working with a telerik grid made in a user control, inside this control there is a checkbox
<telerik:GridTemplateColumn>
<ItemTemplate>
<asp:CheckBox ID="check" AutoPostBack="true" runat="server" OnCheckedChanged="check_CheckedChanged"/>
</ItemTemplate>
</telerik:GridTemplateColumn>
What I need to do is while the "check_CheckedChanged" is happening disable a certain button that is outside the user control (i know this defeats the purpose of the control being independent but that's not something I can change now). This is because the check_CheckedChanged takes too long to execute (as it does a lot of validations) and the user can press the button before its disabled by the result of check_CheckedChanged. By the way, I do have the buttons id in the control if that's info someone needs.
A less than ideal situation, as you've pointed out, but you could use Javascript. In the check_CheckedChanged, write out a Javascript call to a hideButton() function, which is outside of the user control.
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "script", "hideButton();", true);

LinkButton not firing ASP.NET validators

I have a form that currently uses an control to submit a form. Everything works perfectly. So now the new requirement is for the "submit' button to be a link. Changing it to a LinkButton control, without changing a SINGLE other thing, breaks the validation.
There is a bit too much code to post in a SO question and I know there's a bit of a lack of detail here, but is there any reason why a LinkButton wouldn't fire ASP.NET validation the same way a Button control would? In theory, they should both operate exactly the same, no?
The current submit button:
<asp:Button ID="btnSubmit" TabIndex="9" Text="Send" ValidationGroup="Forward" runat="server" />
The new submit button:
<asp:LinkButton ID="btnSubmit" TabIndex="9" Text="Send" ValidationGroup="Forward" runat="server" />
The Link button should fires the validation the same way a normal button does, my concerns in your case would be the following:
make sure these is nothing in the server side code stopping this.
make sure in the javascript code there is nothing stopping the "
ASP.NET controls that fire validation has a property called CauseValidation
Be sure all controls should fire validation, has this property set to True
Add attribute CauseValidation="True" to your control but if you want to fire this at particular line at code behind you can use validate the form by the following code:
FormID.Validate();
I know this is old but it has never answered. Did your validator have a "controlTovalidate"? Currently it would appear as if the validator was not firing but in reality it is. It just does not have anything that it is 'watching'. Hope if anyone reaches this thread that this helps even if it is just a little bit.
I was unable to determine the cause of this issue but was able to solve it:
I set the CausesValidation="false" and added at the top of the onclick event this.Validate(linkButton.ValidationGroup) this allows the event to get to the code behind and validation to occur.

validation problem in asp.net

I am using Page.Isvalid function in my web page.I have two buttons in my web page namely "save" and "generate".when i click the save button the validation summary will be invoked in which all the validations in this page will be shown.
Now I dont want to show a particular validation message for the "Save" button, but the same validation message should be shown specifically to "generate" button in the same page.
But i am using Page.Isvalid in the "save" button click which is displaying all the validation messages in the page.
Any help would be deeply appreciated.Thanks
You can use ValidationGroup(s) to do this.
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" />
<asp:RequiredFieldValidator ID="R1" runat="server"
ErrorMessage="*"
ValidationGroup="GenerateOnly"
ControlToValidate="TextBox1" />
<asp:Button ID="Generate" runat="server" Text="Generate"
ValidationGroup="GenerateOnly" />
<asp:Button ID="Save" runat="server" Text="Save" />
</div>
</form>
This example triggers the validator if Generate is clicked, but not when Save is clicked, and also works when calling Page.IsValid in the buttons onclick function.
not entirely sure what you mean but here goes.
If you want both the save and generate buttons to generate validation messages then why not move the Page.Isvalid along with the validation code into another method. Call this method from both the save and generate methods.
If I've got the wrong end of the stick please let me know a bit more.
Cheers Tigger
Ya buddy if you have to call the same function for two different buttons it is not possible without the concept of overloading. Otherwise you have to create two methods.
But I'am not sure as i am a begginer

How to ask the user for confirmation of an action with a popup box?

I'm currently coding a button which will delete a record from a database if clicked. However, I want some sort of confirmation after they click it so there are no accidents. I was imagining a popup box that tells them they are about to delete this record with two buttons cancel and OK. If cancelled, nothing happens, but if OK is pressed, then the server would execute the delete as coded. How would I do this in asp/vb?
Here is a button with a confirmation message :
<asp:Button runat="server" ID="btnDelete"
OnClick="btnDelete_Click"
OnClientClick="return confirm('Do you want to delete the record ? ');" />
Here is the way to add confirm client script at server side :
btnDelete.Attributes.Add("onclick",
"return confirm('Do you want to delete the record ? ');")
Adding Client-Side Message Boxes in your ASP.NET Web Pages is a great tutorial to make client-side confirmation messages like this:
Using ASP.NET & VB.NET (Don't forget to read part2.)

Preventing Double Clicking with Server Side Validation

I am trying to prevent users from double clicking on the submit button for a page I'm updating. The problem is that there is server side validation that has to be done to determine if the user has to do any updates before we can move on. I currently have the following code on my submit event for my form.
<asp:Button ID="SubmitPayment" runat="server" OnClientClick="this.disabled='true';" UseSubmitBehavior="false" OnClick="SubmitPayment_Click" Text="Submit" />
Where this becomes an issue is where the page does not pass validation. In this instance everything I have tried to enable the button has failed. It's hard for them to resubmit corrected information with the submit button disabled. I have tried both of the following methods at the end of my validation to re-enable it.
SubmitPayment.Enabled = true;
SubmitPayment.Attributes.Add("disabled", "false);
What must I do to re-enable this control? This is in Visual Studio 2005. Thanks in advance.
-edit-
The approach that I used was as follows. I added an additional decoy button that was disabled and had the display css property set to none. I then used javascript that would hide the submit button and show the decoy button in the OnClientClick event. Finally, the end of the server side method would update the css properties on the buttons to hide and show them afterwards.
Code segments are as follows. Thanks again for the help
function PreventDoubleClick()
{
var sp = document.getElementById("SubmitPayment");
var db = document.getElementById("DecoyButton");
sp.style.display = "none";
db.style.display = "inline";
}
<asp:Button ID="SubmitPayment" runat="server" OnClientClick="javascript:PreventDoubleClick();" UseSubmitBehavior="false" OnClick="SubmitPayment_Click" Text="Submit" />
<asp:Button ID="DecoyButton" Enabled="false" runat="server" style="display:none;" Text="Please Wait..."/>
DecoyButton.Style.Add("display", "none");
SubmitPayment.Style.Add("display", "inline");
I have had a similar problem before and the best solution I came up with was to hide the button and replace it with a please wait (or validating) message. If it fails validation you can then show the button again

Resources