How to pass a querystring using RegisterStartupScript?

1k Views Asked by At

I have this in my code behind:

ScriptManager.RegisterStartupScript(this, typeof(string), Guid.NewGuid().ToString().Replace("-", ""), "window.setTimeout(\" $('#" + calendar.ID + "').fullCalendar({header: {left: 'prev,next today',center: 'title',right: 'month,agendaWeek,agendaDay'},aspectRatio: 2.2,editable: true,events: " + sJSON + ", eventClick: function(event) { OpenModal('Novo Compromisso','100%','500px','/agenda/form.aspx?compromissoid=event.id');}});\",100);", true);

It gets some data and load the event property of the calendar. On the eventClick I want to access the event.id to open a modal window and edit the event. But the querystring is being set to 'event.id' literally.

I checked to see if the event.id has a value at all. It has 'cause it appears on the alert() function as seen below.

ScriptManager.RegisterStartupScript(this, typeof(string), Guid.NewGuid().ToString().Replace("-", ""), "window.setTimeout(\" $('#" + calendar.ID + "').fullCalendar({header: {left: 'prev,next today',center: 'title',right: 'month,agendaWeek,agendaDay'},aspectRatio: 2.2,editable: true,events: " + sJSON + ", eventClick: function(event) { alert(event.id); OpenModal('Novo Compromisso','100%','500px','/agenda/form.aspx?compromissoid=event.id');}});\",100);", true);

So, how can I use event.id value as my querystring?

2

There are 2 best solutions below

1
On BEST ANSWER

In your OpenModal call, change your url from this '/agenda/form.aspx?compromissoid=event.id' to this: '/agenda/form.aspx?compromissoid=' + event.id

    ScriptManager.RegisterStartupScript(this, typeof(string), Guid.NewGuid().ToString().Replace("-", ""), "window.setTimeout(\" $('#" + calendar.ID + "').fullCalendar({header: {left: 'prev,next today',center: 'title',right: 'month,agendaWeek,agendaDay'},aspectRatio: 2.2,editable: true,events: " + sJSON + ", eventClick: function(event) { alert(event.id); OpenModal('Novo Compromisso','100%','500px','/agenda/form.aspx?compromissoid=' + event.id);}});\",100);", true);
0
On

If you are getting event.id then use it like this compromissoid='+event.id+''

ScriptManager.RegisterStartupScript(this, typeof(string), Guid.NewGuid().ToString().Replace("-", ""), "window.setTimeout(\" $('#" + calendar.ID + "').fullCalendar({header: {left: 'prev,next today',center: 'title',right: 'month,agendaWeek,agendaDay'},aspectRatio: 2.2,editable: true,events: " + sJSON + ", eventClick: function(event) { alert(event.id); OpenModal('Novo Compromisso','100%','500px','/agenda/form.aspx?compromissoid='+event.id+'');}});\",100);", true);