Send an ok/cancel confirm with database data? ASP.Net VB - asp.net

Can someone help me with this:
I want to send a confirm message to the user if a button is clicked. But the problem is that I want server data on the message.
For Example:
|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
| You are going to delete |
| 4 messages, are you sure? |
| |
| |OK| |Cancel| |
|___________________________|
The number 4 is brought from database with a Stored Procedure.
If the user clicks OK it should do some other code, if cancel is clicked, it should just return...
This is for a website on ASP.net using Visual Basic.
Please help!
Update:
After #T.S. answer I came up with this:
'Method for receiving the number...
'messages = numberReceived
Page.ClientScript.RegisterStartupScript(Me.GetType, "Confirmation", "<script> if (confirm('You will delete " & messages.ToString & " messages, are you sure?')) { ConfirmOnClean() }; </script>", False)
And the javascript function ConfirmOnClean() gets called correctly. What can I do to call a method on the codebehind after the user clicked OK?
Update:
I Finally solved it by Just adding a hidden field on the form:
<asp:HiddenField ID="cleanStatus" Value="dontClean" runat="server" />
And then on the Confirm on clean function I just did:
function ConfirmOnClean() {
$('#<%=cleanStatus.ClientId %>').val('clean');
__doPostBack('<%=btnClean %>','');
}
And on the Page_Load method on my codebehind I added:
If cleanStatus.Value.Equals("clean") Then
OnConfirm() 'Method for calling the stored procedure for deleting the messages.
End If
I hope this helps someone!

Your question is lacking concrete code. So here is one option:
Assume you have some Id. You call stored proc
Dim message as String
Using cmd as new SqlCommand(...
cmd.ExecuteNoQuery()
' retrieve your parameters here
message = cmd.Parameters(0).Value
End Using
Now code returns to the user with the values you retrieved. You can register script block to show the message immediately on the page http://msdn.microsoft.com/en-us/library/z9h4dk8y%28v=vs.110%29.aspx
When user User clicks Ok, you can, for example, set a hidden field with a value and invoke postback. YOur aspx page will read the value and invoke DB-call to delete values.
You need to provide more details to get more concrete solution here

Related

How can i populate and optimize DropDownList from WebService using Select2.js

I'm working on customer selection module that will autocomplete while typing. It seems that Select2.js would do the job, I already managed to populate my dropdownlist but on the back-end (.cs file) with a simple data binding.
The problem is, I am only working with a sample data of 15 customers so the performance is just fine, i am expecting an actual data of almost 2000 customers so just by binding would messed up the performance.
here is my code for the binding event and implementation of select2.js
.aspx file:
<asp:DropDownList runat="server" ID="ddlCustomers" CssClass="form-control" async="">
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
.cs file:
protected void BindDropDownCustomers()
{
DataTable dt = SharedClass.getAPI("CustomerProfile_All"); //Returns Data from Webservice
DataColumn newColumn = new DataColumn();
//just formating the display
newColumn.ColumnName = "FullName";
newColumn.DataType = System.Type.GetType("System.String");
newColumn.Expression = "Cust_Last_Name+', '+Cust_First_Name";
dt.Columns.Add(newColumn);
ddlCustomers.DataTextField = "FullName";
ddlCustomers.DataValueField = "SmartCardID";
ddlCustomers.DataSource = dt.DefaultView;
ddlCustomers.DataBind();
ddlCustomers.Items.Insert(0, new ListItem("Select Customer", ""));
}
select2.js script:
$('#<%= ddlCustomers.ClientID %>').select2({
placeholder: "Select customer",
minimumResultsForSearch: 2,
minimumInputLength: 3,
allowClear: true
});
I want something like, after the user enters a minimum of 3 characters, a query will be executed and get all related data that will populate the dropdownlist and limit or optimize the display at the same time.
Well, In my opinion, running a loop 2,000 times on a client machine using javascript (it would be better to check if the chars that were typed by user were more than 3 here) is fine instead of making a call to the server and opening SQL Connection to query something whenever user types something. Think of it as when the network will be slow the lag would be more and what if tens of thousands users make the same call to the server and server is just searching through the records? Well that was just an opinion. Of course, you can decide what is suitable for you.
If you still want to do it, you can either look out for some paid controls or see if there is one in ajax toolkit.
Moreover, if you want to do it in a custom way then you can use jquery-ui autocomplete to achieve the task.
I am not going to give the source code to do that but here is the rough idea that you might want to do:
Show a basic few records on load
Hook up jQuery-UI autocomplete to the text box that is searching and returning the results from the db
Add Custom HTML when you get the respond as it is in your HTML page and Hook up jquery/javascript events to select the relevant values.
Hope this gives a rough idea.

How to simulate onblur event with Robot Framework

I am automating login scenario of an application.
The execution steps are as below:
Select the Country
Enter the Username
Enter the Password
Click on Login Button.
Actually after entered the username, application validates the country and username in database exists or not.
When tried to automate through robot framework, this validation is not called and so unable to login (actually login button is clicked through script, but no error message or no response user is in same page).
When i verified exact scenario it calling the validation, comes to know that
validation is called on onblur of the usename element onblur="getlocation()".
I tried to simulate this by give tabout from username field through script as
Press Key ${element path} \\9 but it is not working always out of 10 run only 3 or 4 times it working.
Is there any way we can do 'blur` action on the element in robot framework
In the Selenium2Library for robot, there is a special keyword for that:
Simulate <element> <event>
In my keyword definition it looks like this:
I Enter The New Password
[Arguments] ${text}
Input Text ${INPUT_ELEMENT_PASSWORD} ${text}
Simulate ${INPUT_ELEMENT_PASSWORD} blur
http://robotframework.org/Selenium2Library/Selenium2Library.html#Simulate
I hope that helps, it took us a while to figure out what was missing in the test.
Just to save few minutes of googling.
Simulate
is deprecated. Use
Simulate Event
instead

Text Property Confusion

I am not sure what is happening, maybe someone can clarify.
The scenario is simple, I have a form that I am submitting to update a DB.
So on Page_Load, I set each field to the current value in the current object.
Example:
txtFirstName.Text = empInfo.FirstName // FirstName = Jane
txtLastName.Text = empInfo.LastName
// Etc
Now at runtime it may be edited by the user, typical textbox stuff.
When I run my button click to update it will always return the assigned Text value previously and not the new user-edited value.
Let's say the user edits the field:
First Name: [ Joe ]
If I were to print txtFirstName.Text, it is STILL Jane
Note: This does not happen if the Text property is never set, in that case, it works as expected
Sounds like the code that assigns your txtFirstName.Text control/property is running again after post back and overwriting the new value. Make sure that you initialization code is wrapped in a check for (!IsPostBack) to ensure it is only run the first time the page is accessed an not with every post back (update) to the page.
Post your Page_Load code or where you do the initialization and we can probably confirm this is the issue.

Terminate the session on IIS

I have a requirement that is :--
On click of ‘Logout’ link, popup message “This will terminate the session and close the browser. Do you want to continue?” with Yes and No buttons. On click of ‘Yes’, session should be terminated in IIS server and current tab of browser closed.
To implement this I have writen below piece of code but I dont know how to terminate the session on IIS
<script language="vbscript">
Function OnClickLogout()
dim Answer, msg
Msg = "This will terminate the session and close the browser. Do you want to continue?"
Answer = MsgBox(Msg, vbYesNo + vbCritical, "Error")
if Answer = vbYes then
window.close
else
'Retrun to the previous page
end if
End Function
</script>
Could anyone please suggest me how to do this in vbscript. My website is in ASP but its a legacy application so I have to do the code!!!
Couldn't you simply use JavaScript? We us it all the time at work in our ASP Classic projects. Something like that to start off:
function DeleteProductGroup(){
var r=confirm("Are you sure you want to delete this product group?");
if (r==true){//here goes the code if user presses YES
}
else{//here goes the code if user presses NO
}
}

ASP.Net links won't disable if done during postback

I'm still fairly new to ASP.Net, so forgive me if this is a stupid question.
On page load I'm displaying a progress meter after which I do a post back in order to handle the actual loading of the page. During the post back, based on certain criteria I'm disabling certain links on the page. However, the links won't disable. I noticed that if I force the links to disable the first time in (through debug) that the links disable just fine. However, I don't have the data I need at that time in order to make the decision to disable.
Code Behind
If (Not IsCallback) Then
pnlLoading.Visible = True
pnlQuote1.Visible = False
Else
pnlLoading.Visible = False
pnlQuote1.Visible = True
<Load data from DB and web service>
<Build page>
If (<Some Criteria>) Then
somelink.Disable = True
End If
End If
JavaScript
if (document.getElementById('pnlQuote1') === null) {
ob_post.post(null, 'PerformRating', ratingResult);
}
ob_post.post is an obout js function that does a normal postback and then follows up with a call to the server method named by the second param. then followed by the call to a JavaScript method named by the third param. The first parameter is the page to post back to. A value of null posts back to the current page.
The post back is working fine. All methods are called in the correct order. The code that gives me trouble is under the code behind in bold. (somelink.disabled = True does not actually disable the link) Again, if I debug and force the disabling of the link to happen the first time in, it disables. Does anyone know what I might do to get around this?
Thanks,
GRB
Your code example is using the IsCallBack check, while the question text talks about the IsPostback Check. I'd verify that you're using Page.IsPostBack in your code to turn off the links.

Resources