I have created a User Control in which I use a JQuery Plugin (DataTables).
I would like to refresh the User Control when I click on a button that I have generated inside the User Control like this :
_DT += "<button id=\"validConf\" runat=\"server\" type=\"button\" class=\"btn btn-success\" onclick=\"$('#modalConfig_" + ID + "').modal('hide');\">Valid</button>"
Now, in my Page I have the following code :
<asp:ScriptManager EnablePartialRendering="true" ID="ScriptManager1" runat="server" EnablePageMethods="true"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<UC:Grille runat="server" ID="Grille1"/>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="validConf" />
</Triggers>
</asp:UpdatePanel>
It returns this error : "Unable to find control in Update Panel for trigger"
Am I not doing it the good way or am I missing something ? Is it even possible ?
Related
I'm a newbie to ASP.net (vb), and i'm working with the timer controls. I've once again researched the answer to this and done as said (overloading prerender method). My problem is I have a master page which i've added a timer control, in order to update a count down field, on going to the sites index page i keep getting the error : "Script controls may not be registered before PreRender." The timer works well on other pages except the index page.
<form id="fMain" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:Timer ID="timer1" runat="server" Interval="1000" OnTick="timer1_tick"></asp:Timer></div>
<div>
<asp:UpdatePanel id="updPnl" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Literal ID="litTimer" runat="server"></asp:Literal>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="timer1" EventName ="tick" />
</Triggers>
</asp:UpdatePanel>
</div>
The Codebehind:
Sub timer1_tick() Handles timer1.Tick
ltr1.text = "test"
End Sub`
Thank you in advance.
This is because you are using Telerik controls and have overridden the OnPreRender method.
You need to add the following to this method:
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
i need to be able to update the label text whenever i want without clicking on a button or something similar to that. the update happens based on server-client logic. i tried to use java script, but when i call the script from a function i wrote it doesn't work. now i'm trying to use updatepanel and no luck so far. i tried to use
UpdatePanel1.Update();
but it didn't refresh the label. the label defined inside the updatepanel:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="Label3" runat="server" Text="Label" AccessKey="l"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
is there a away to force it to refresh?
If you just want to update your label from javascript you can try this function:
<script type="text/javascript">
function updateLabel(newValue) {
$('#<%= Label3.ClientID %>').val(newValue);
}
</script>
I have a master page "PartialUpdate.Master" and 2 simple content pages "WebForm1.aspx" and "WebForm2.aspx"
WebForm1.aspx/WebForm2.aspx: the content-pages just display their filename
The master page "PartialUpdate.Master" has 2 buttons and a ContentPlaceHolder
in an UpdatePanel. When clicking on a button I want to see the corresponding content-page
Here's what it looks like...
PartialUpdate.Master :
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
Master Page
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional"
runat="server">
<ContentTemplate>
<asp:Button ID="btnForm1" CommandArgument="WebForm1.aspx"
runat="server" Text="Form1" OnClick="ChangeForm_Click" />
<asp:Button ID="btnForm2" CommandArgument="WebForm2.aspx"
runat="server" Text="Form2"
OnClick="ChangeForm_Click" />
<hr />
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnForm1"
EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="btnForm2"
EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</div>
</form>
</body>
The code behind of PartialUpdate.Master.cs
protected void ChangeForm_Click(object sender, EventArgs e)
{
Button btn = sender as Button;
Response.Redirect(btn.CommandArgument);
}
Problem here is that Response.Redirect() triggers a full-page postback.
I just want the Master to refresh the content located in the 'ContentPlaceHolder' asynchronously (that's why I added the AJAX UpdatePanel)
In other words, I'd like to dynamically change the content-page that the Master is displaying whitout causing a full-page postback.
Is this possible? If so how?
thank you
Chris
You can call with WebRequest in ajax call and write the content you recieve to the page...
But you can`t "knowing" the browser that you want to redirect to another page without post back.
Working on a page with multiple sections.
at the very top there is a "status" label.
beneath that is a section for adding new data...
beneath that is a section for updating data...
beneath that is a section for deleting data...
and...
beneath that is a section for viewing data... (repeater)
not even really concerned about the updating and deleting sections at this point... just stating that they are there so show the general layout of the page.
Now.. when I go to add new data, the submit button is set up as a trigger for an update panel that surrounds the repeater at the bottom of the page... that works perfectly... BUT its not removing the text from the text boxes or updating the status label because the page is only partialy posting back... (obviously)
when you click the button i also want the label to display ("You added data") and the text boxes to be emptied out... SOOO... i thought i'd be tricky and put an update panel around the status and the adding and setting their triggers to the same button... doesnt seem to work :-\ i usually dont bother with update panels... but this page has the potential to have A LOT of text data and formatting...
any ideas?
Figgured it out.
<asp:updatepanel id="updatepanel1" runat="server">
<contenttemplate>
<asp:label id="lblstatus" runat="server /> <br />
</contenttemplate>
<triggers>
<asp:asyncpostbacktrigger controlid="btnaddkey" eventname="Click" />
</triggers>
</asp:updatepanel>
<asp:updatepanel id="updatepanel2" runat="server">
<contenttemplate>
<asp:textbox id="tbxkeyname" runat="server />
<asp:textbox id="tbxkeytitle" runat="server />
<asp:textbox id="tbxkeyvalue" runat="server />
</contenttemplate>
<triggers>
<asp:asyncpostbacktrigger controlid="btnaddkey" eventname="Click" />
</triggers>
</asp:updatepanel>
<asp:button id="btnaddkey" runat="server" text="submit" OnClick="btnAddKey_Click" />
<asp:updatepanel id="updatepanel3" runat="server">
<contenttemplate>
<asp:repeater id="rptkeyview" runat="server">
...
</asp:repeater>
</contenttemplate>
<triggers>
<asp:asyncpostbacktrigger controlid="btnaddkey" eventname="Click" />
</triggers>
</asp:updatepanel>
Above is the basic layout of the page.... keep in mind that there is other content between each of the update panels... (i still need to add functionality to edit and delete as well)
With the btnaddkey click the following code occurs:
protected void btnAddKey_Click(object sender, EventArgs e)
{
Configuration toConfiguration = new Configuration();
toConfiguration.Title = tbxKeyTitle.Text;
toConfiguration.Name = tbxKeyName.Text;
toConfiguration.Value = tbxKeyValue.Text;
toConfiguration.AddKey();
lblStatus.Text = "New Key Added.";
BindKeys();
tbxKeyName.Text = "";
tbxKeyTitle.Text = "";
tbxKeyValue.Text = "";
}
Problem was that i need the labels and the text boxes (each in their own update panels) to all update on that one click....
using the above code it is working now
Are you saying you want multiple updatepanels on the same page?
If so see this
when i using ajax control but control tick every 1 secound and when i click other control the control not focus in selection my control when timer tick
That particular timer must be placed inside the update panel.
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Timer ID="Timer1" runat="server" Interval="1000" ontick="Timer1_Tick">
</asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>
Here's another way to do it:
http://mattberseth.com/blog/2008/05/bug_bash_enablingdisabling_the.html
This is how I approached it (note that the server-side tags for Timer1 and the "txtSymbol" textbox are approached differently):
<asp:Content ID="HeadContent" runat="server" ContentPlaceHolderID="HeadContent">
<link rel="stylesheet" type="text/css" href="/Website1/Styles/lessantique.css" />
<script type="text/javascript">
function pageLoad(sender, args){
// fetch the timer components
var timer = $find('<%= this.Timer1.ClientID %>');
// fetch the INPUT element
var textbox = $get('Content1_txtSymbol');
$addHandler(textbox, 'focus', Function.createDelegate(this, function(){
// disable the Timer so we don't refresh the page
// while the user is entering the data
timer._update(false, timer.get_interval());
}));
$addHandler(textbox, 'blur', Function.createDelegate(this, function(){
// re-enable the Timer
timer._update(true, timer.get_interval());
}));
}
</script>
</asp:Content>
regarding the server side code for the timer listed in the previous response, that approach did not work for me since I have more than one update panel, where the text box is not in the same panel that uses the timer. In that case I followed the advice at http://forums.asp.net/t/1632054.aspx/1, where a new panel is implemented, as such:
<asp:UpdatePanel runat="server" ID="UpdatePanel3" UpdateMode="Conditional" ChildrenAsTriggers="false" >
<ContentTemplate>
<asp:Timer runat="server" id="Timer1" Enabled="true"
Interval="2000" OnTick="Timer1_Tick" />
</ContentTemplate>
</asp:UpdatePanel>
Despite the above not producing errors, the results were still unsatisfactory, therefore the client-side approach.