Mixing a client-side/server-side event

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm hoping this is a classic question, but the answer to it would help me
with a lot of things.

As you can see below, this code will never display the "Getting data...." text
in the lblCheck - because it needs to do a round-trip to the server - first.
And when it gets back, my other routine will over-write the text as "34
records found"

Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSearch.Click

Me.lblCheck.Text = "Getting data....."
SearchActionList()

End Sub
 
Hi,
Add this code in form load or any other appropriate event:
btnSearch.Attributes.Add("onClick","return javascript:DisplayLabelText();")
After adding this attribute, your asp:button (search button) will call the
javascript function first then submit the form if the function returns true,
otherwise it halts further execution if false is returned.
Code for javascript function would be something like this:
<script language="Javascript">
function DisplayLabelText()
{
document.getElementsByTagName('lblCkeck').innerText = 'Getting Data..';
return true;
}
</script>
Although i may not written exact syntax but i hope you have got an idea
 
jonefer said:
I'm hoping this is a classic question, but the answer to it would help me
with a lot of things.

As you can see below, this code will never display the "Getting data...."
text
in the lblCheck - because it needs to do a round-trip to the server -
first.
And when it gets back, my other routine will over-write the text as "34
records found"

Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSearch.Click

Me.lblCheck.Text = "Getting data....."
SearchActionList()

End Sub

Don't hold me to it, but if you're using .Net 2.0, can't you use this?

Label1.Text = Server.HtmlEncode("Getting data.....")

I noticed it populated the label before it made the round trip when I pushed
the Submit button.
 
Tried it and understand what it is supposed to do, but I will have to request
that you help me get the javascript exactly right, since I am unfamiliar with
what it needs exactly

the error I am recieving is: 'Error: expected ";"

and as you know, you ended all your lines with that.
 
Hi,
Below code is working perfectly well in my machine:
[1] Javascript Code:
<script language="Javascript">
function DisplayLabelText()
{
var obj = document.getElementById('lblCheck');
obj.innerText = 'Getting Data..' ;
return true;
}
</script>
[2]Code you will write in page load:
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
btnSearch.Attributes.Add("onClick","javascript:return
DisplayLabelText();");

}
 
Ok, I implemented it, however --- it still doesn't do anything.

I read something about the property: OnClientClick

Here is a sample that actually does something:
<asp:Button ID="btnAlert" runat="server" OnClientClick="alert('Are you sure
you want to do this? (I dont do anything really.)');" Text="Client Alert"
UseSubmitBehavior="false" />

Can you help me modify it so that it just changes the text in lblCheck?


Manish Bafna said:
Hi,
Below code is working perfectly well in my machine:
[1] Javascript Code:
<script language="Javascript">
function DisplayLabelText()
{
var obj = document.getElementById('lblCheck');
obj.innerText = 'Getting Data..' ;
return true;
}
</script>
[2]Code you will write in page load:
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
btnSearch.Attributes.Add("onClick","javascript:return
DisplayLabelText();");

}
--
Hope this helps.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.



jonefer said:
I'm hoping this is a classic question, but the answer to it would help me
with a lot of things.

As you can see below, this code will never display the "Getting data...." text
in the lblCheck - because it needs to do a round-trip to the server - first.
And when it gets back, my other routine will over-write the text as "34
records found"

Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSearch.Click

Me.lblCheck.Text = "Getting data....."
SearchActionList()

End Sub
 
Ok, these two pieces effectively work to make the label say "Getting Data"
However - Now the SearchActionList() function that I run the code-behind
file doesn't run anymore. Did the client-side scripting replace the
code-behind OnClick?

[1]
function doClientCode(msg){
document.getElementById('<%=lblCheck.ClientID %>').innerText = msg;
document.getElementById('<%=btnSearch.ClientID %>').disabled = true;
}

[2] Code on in the Asp: button tag
<asp:Button ID="btnSearch" runat="server" onclientclick="javascript:return
doClientCode('Getting data....');" Text="Search" />





Manish Bafna said:
Hi,
Below code is working perfectly well in my machine:
[1] Javascript Code:
<script language="Javascript">
function DisplayLabelText()
{
var obj = document.getElementById('lblCheck');
obj.innerText = 'Getting Data..' ;
return true;
}
</script>
[2]Code you will write in page load:
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
btnSearch.Attributes.Add("onClick","javascript:return
DisplayLabelText();");

}
--
Hope this helps.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.



jonefer said:
I'm hoping this is a classic question, but the answer to it would help me
with a lot of things.

As you can see below, this code will never display the "Getting data...." text
in the lblCheck - because it needs to do a round-trip to the server - first.
And when it gets back, my other routine will over-write the text as "34
records found"

Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSearch.Click

Me.lblCheck.Text = "Getting data....."
SearchActionList()

End Sub
 
It works, but now the Code-Behind routine connected to the button doesn't work.
How can I make the client-side run as well as the

Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSearch.Click

SearchActionList()

End Sub

They need to both work.
Manish Bafna said:
Hi,
Below code is working perfectly well in my machine:
[1] Javascript Code:
<script language="Javascript">
function DisplayLabelText()
{
var obj = document.getElementById('lblCheck');
obj.innerText = 'Getting Data..' ;
return true;
}
</script>
[2]Code you will write in page load:
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
btnSearch.Attributes.Add("onClick","javascript:return
DisplayLabelText();");

}
--
Hope this helps.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.



jonefer said:
I'm hoping this is a classic question, but the answer to it would help me
with a lot of things.

As you can see below, this code will never display the "Getting data...." text
in the lblCheck - because it needs to do a round-trip to the server - first.
And when it gets back, my other routine will over-write the text as "34
records found"

Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSearch.Click

Me.lblCheck.Text = "Getting data....."
SearchActionList()

End Sub
 
Back
Top