[RESOLVED] [2008] Confirm before potentially long query
I don't know enough about web development yet to get my logic straight, but I'm sure you do. I'll try to make this brief.
Two TextBoxes populate my Parameters for an Oracle query - neither TextBox is required - if they are both empty my query will return everything and will take some time to execute. My search button runs the query and is a trigger for an UpdatePanel that holds the populated GridView.
Everything works fine, except I want to do this:
If both TextBoxes are empty, I'd like to warn the user that this could take some time - do you want to execute the query or forget it and fill in some values in the TextBox(es)?
I realize the two technologies that I'll need to use are both client side and server side, so I need some help.
-Do I popup a confirm from the codebehind and go from there? Can I even get the users click value?
-Check the TextBoxes from the clientside and call my codebehind if the user clicks ok? Can I do this?
-Do something completely different?
Let me know if I didn't explain that well. Thanks for pushing this chump web developer in the right direction! :)
Re: [2008] Confirm before potentially long query
Quote:
Check the TextBoxes from the clientside and call my codebehind if the user clicks ok? Can I do this?
This one. Yes.
Re: [2008] Confirm before potentially long query
Thanks. I'm a little stuck again.
Here is what I want to run in VB:
vb.net Code:
If DirectCast(Session("gridBuilt"), Boolean) = False Then
BuildGrid()
End If
If Me.sellOffStart.Text = String.Empty OrElse Me.sellOffEnd.Text = String.Empty Then
Me.sellOffStart.Text = "01/01/1900"
Me.sellOffEnd.Text = "12/31/9999"
End If
Dim v_rBLL As New V_REPCUSTOMFIELDDATABLL()
Dim dt As Data.DataTable = v_rBLL.GetSellOffDates( _
"%" & Me.licensorNum.Text & "%", "%" & Me.projectName.Text & "%", Me.sellOffStart.Text, Me.sellOffEnd.Text)
Me.GridView1.DataSource = dt
Me.GridView1.DataBind()
Me.countLabel.Text = dt.Rows.Count.ToString() & " records returned"
Session("gridBuilt") = True
Assuming I call this "RunQuery" am I on the right track with this onclick function?
Code:
<script type="text/javascript">
function CheckTextBoxes() {
var t1 = document.getElementById('TextBox1');
var t2 = document.getElementById('TextBox2');
if((t1.value == "") && (t2.value == "")) {
if(confirm('Are you sure?')) {
CallPageMethod(); // Call RunQuery in .vb
} else {
return false; // Do nothing
}
} else {
CallPageMethod(); // Call RunQuery in .vb
}
}
function CallPageMethod() {
PageMethods.RunQuery(onSucceeded, onFailed);
}
</script>
This has to be a Shared method though correct? Or am I looking to do something that Implements the ICallBackEventHandler?
Or maybe I should just write a big message on the page instead of trying to use a popup. Thanks again for the help.
Re: [2008] Confirm before potentially long query
I fear you're complicating it slightly.
You cannot do this
Code:
else {
CallPageMethod(); // Call RunQuery in .vb
}
You will have a button on your page which the user will click. This is what calls the codebehind method by submitting the page. You want to 'intercept' this button's click event so that you can cancel the submission. So,
Code:
Button1.Attributes.Add("onclick","return CheckTextBoxes();")
Now, if CheckTextBoxes() returns false, the button won't submit. If it returns true, it will hit your codebehind method.
Re: [2008] Confirm before potentially long query
Wow, I was making that hard! This is awesome. I am very close as I have this working on a sample page but I'm still having trouble on my actual page.
Actual:
Code:
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<script type="text/javascript">
function CheckTextBoxes() {
var t1 = document.getElementById('productNum');
var t2 = document.getElementById('productDescrip');
if((t1.value == "") && (t2.value == "")) {
if(confirm('Are you nuts?')) {
return true;
} else {
return false;
}
}
}
</script>
<div class="post">
<div class="title">Licensor By Product Number</div>
Use this form to search for all contracts which are associated with a certain product.
<fieldset>
<asp:UpdateProgress ID="UpdateProgress1" runat="server">
<ProgressTemplate>
<div class="loading">
<img alt="Loading..." src="images/loading.gif" /><br />
Executing Query
</div>
</ProgressTemplate>
</asp:UpdateProgress>
<asp:Label ID="productNumLabel" runat="server" Text="Product Number" class="label"></asp:Label>
<asp:TextBox ID="productNum" runat="server" class="input"></asp:TextBox>
<asp:Label ID="productDescripLabel" runat="server" Text="Product Name" class="label"></asp:Label>
<asp:TextBox ID="productDescrip" runat="server" class="input"></asp:TextBox><br /><br />
<asp:Button ID="searchButton" runat="server" Text="Search" class="button" />
<asp:Button ID="clearButton" runat="server" Text="Clear" class="button" />
</fieldset>
</div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="queryTime" runat="server" Text="" class="countLabel"></asp:Label><br />
<asp:Label ID="countLabel" runat="server" Text="" class="countLabel"></asp:Label>
<asp:GridView ID="GridView1" runat="server" class="grid" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="AGREEMENTS_ABBR" HeaderText="Licensor Number" />
<asp:BoundField DataField="FIELD_VALUE" HeaderText="Contract Name" />
<asp:BoundField DataField="AGREEMENTS_NAME" HeaderText="Project Name" />
<asp:BoundField DataField="LEVELS_ABBR" HeaderText="Product Number" />
<asp:BoundField DataField="LEVELS_NAME" HeaderText="Product Description" />
</Columns>
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="searchButton" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</asp:Content>
' Behind
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.searchButton.Attributes.Add("onclick", "return CheckTextBoxes();")
End Sub
A test version of this with two TextBoxes, a Button, ScriptManager, UpdatePanel, UpdateProgress and a Label works. I've been staring at this since you last posted. What in the world am I missing now? I'm sure its something simple.
I think I'll owe you a beer after this thread.
Re: [2008] Confirm before potentially long query
Let's start really simple...
In your page load,
Code:
Me.searchButton.Attributes.Add("onclick", "alert('Hello');")
Now try it. When you click the button, do you get the alert?
If yes, try replacing it with a some other javascript, such as:
(should not submit the page)
Code:
return confirm('Do you really want to search for something?');
(confirm box!)
If that's all fine, then the call to CheckTextBoxes() should work. Did you know you can debug javascript in VS 2008?
You should try placing a breakpoint at the first line of code in the CheckTextBoxes() method. If the breakpoint doesn't hit for you, then don't waste time trying to figure it out right now. Just place an alert as the first line in that function's body, do you get that alert?
Re: [2008] Confirm before potentially long query
Oh, I clicked submit and just saw what the problem was.
Code:
var t1 = document.getElementById('productNum');
var t2 = document.getElementById('productDescrip');
At runtime, those elements will not have the id 'productNum' and 'productDescrip'. Do a view source on the rendered page and you'll see that it's something else. You need to let your CheckTextBoxes method know, somehow, the new IDs.
I suggest:
Code:
function CheckTextBoxes(txt1, txt2)
{
var t1 = document.getElementById(txt1);
var t2 = document.getElementById(txt2);
....................
}
And in the codebehind,
Code:
Me.searchButton.Attributes.Add("onclick", "return CheckTextBoxes('" & productNum.ClientID & "','" & productDescrip.ClientID & "');")
PS: I prefer Mountain Dew as a liquid mode of payment. :afrog:
Re: [2008] Confirm before potentially long query
I need to be hand held through this. I owe you a six pack.
Quote:
Originally Posted by mendhak
In your page load,
Code:
Me.searchButton.Attributes.Add("onclick", "alert('Hello');")
Now try it. When you click the button, do you get the alert?
Yes!
Quote:
If yes, try replacing it with a some other javascript, such as:
(should not submit the page)
Code:
return confirm('Do you really want to search for something?');
(confirm box!)
Yes and Yes!
Quote:
If that's all fine, then the call to CheckTextBoxes() should work. Did you know you can debug javascript in VS 2008?
You should try placing a breakpoint at the first line of code in the CheckTextBoxes() method. If the breakpoint doesn't hit for you, then don't waste time trying to figure it out right now. Just place an alert as the first line in that function's body, do you get that alert?
Didn't know that about JavaScript. The breakpoint did not hit but I DID get the alert on the first line.
Re: [2008] Confirm before potentially long query
We may have posted at the same time. Look at #7.
Re: [2008] Confirm before potentially long query
Quote:
Originally Posted by mendhak
We may have posted at the same time. Look at #7.
Genious! I had no idea that the IDs weren't the same at runtime. Shows what I know.
P.S. If I could email a case of Mountain Dew I would. :D
Re: [RESOLVED] [2008] Confirm before potentially long query
Just keep it in mind anytime you're going to use javascript to 'talk' to a control that is either <asp:...> or a control that sits inside another control - It will get changed for diabolical control tree and viewstate purposes which means you need to use .ClientID.
And it's quite alright, I'll just buy myself some MD.
Re: [RESOLVED] [2008] Confirm before potentially long query
Quote:
Originally Posted by mendhak
Just keep it in mind anytime you're going to use javascript to 'talk' to a control that is either <asp:...> or a control that sits inside another control - It will get changed for diabolical control tree and viewstate purposes which means you need to use .ClientID.
And it's quite alright, I'll just buy myself some MD.
Good to know.
And with my new found affection for ASP.NET, I'm sure you'll be seeing a lot of me around here.
Thanks again.