Render Partial


I am displaying question & answers with timer. When I click on ‘Save and Continue’ I need to display next question without reloading the timer. For that I am using renderPartial. But it is reloading the complete page.Please review the attached render and render partial images.Could you please help me. My code is

Render code

$model=new ExamForm;

$qdata = Questions::getQuestion();


Render Partial code

$model=new ExamForm;

$qdata = Questions::getQuestion();

$this->renderPartial('exam',array('model'=>$model, 'qdata'=>$qdata), false,true);

View file code



$cs->registerScriptFile(Yii::app()->baseUrl . '/js/jquery-1.4.4.pack.js', CClientScript::POS_HEAD);

$cs->registerScriptFile(Yii::app()->baseUrl . '/js/jquery.countdown.js', CClientScript::POS_HEAD);

$cs->registerScriptFile(Yii::app()->baseUrl . '/js/countdown.js', CClientScript::POS_HEAD);

$cs->registerCssFile(Yii::app()->baseUrl . '/css/jquery.countdown.css');


<div id="defaultCountdown"></div>


<div class="form" id="exam-grid">

<?php $form=$this->beginWidget('CActiveForm'); ?>

<h3 class="question-title">Question <?php echo $model->minQN ;?> of <?php echo $model->maxQN ;?></h3>

<div class="row">

<input type="hidden" name="question" value="<?php echo $qdata["id"]?>" />

<?php echo "<h2>".$qdata['question']."</h2>";?>


<div class="row compactRadioGroup">

<input type="hidden" name="question" value="<?php echo $qdata["id"]?>" />

<?php echo  CHtml::radioButtonList('answers','',Answers::getAnswers($qdata['id']));?>


<div class="row" align="center">


echo CHtml::ajaxLink(

                   'Save and Continue',


                   array("update" => "#exam-grid","type"=>"POST"),

                   array("href" => Yii::app()->createUrl("exam/next")) 




<?php $this->endWidget(); ?>

</div><!-- form -->





Thanks & regards,


For reload a part of page you should use an ajax link.

The action that answer to the ajax request will do renderpartial.

About timer, I think is better to save it server side and not rely on the timer the user sends you.

I would double check your render and renderPartial. The problem is that you render twice the same view, it is normal that you actually view twice…

I will do this:

render—> exam

within exam there is a variable within that you fill from your controller (the first time only) having the return of a renderPartial calling a _question view file

exam/next on your controller should renderPartial _question…

Thanks Antonio Ramirez. It is working now.

I have another problem. Can you help me.

In render view, I am displaying timer. In render partial view, I am displaying questions and answers. After completing the questions and answers redirecting to ‘complete’ action in same controller. Controller action is working but the view is displaying in place of render partial view. View is not displaying in full page even URL also not changing.

For redirect my code is


Tried also






So the layout doesn’t render twice check it its an ajax request


and if it is use renderPartial or set


in the controller

And yes, for ajax requests page url wont change

The redirect doesn.t work for ajax request, you should use a normal link (non ajax) for complete button.

What you could do too is to send back in the response some json and check if needs a redirect, instead of using header(redirect), like






I didn’t say before because I wasn’t sure about the question …

hi gustavo

i’m new in yii and i’m trying to do a profile manager like yours

can you give-me a little help?

Hi Daniel

It wasn’t me who was developing it, It was gnekkala . I just answered his question.

You can ask him or create a new post for each doubt you have.


yeah, sorry

I was sleeping when I asked xD