c# - Masterpage method returns null when firing a button event in a derived page -
basically on master page have method returns "campaign" params of unique id , user id. works fine until click button in derived page.
the problem when click button in derived page method in master page returns "null". when debugging see correct params.
edit// method returns null:
var campaign = campaignrepository.getcampaignbyid(convertedcampaignid, user.userid);
master page code:
protected void page_load(object sender, eventargs e) { string securitytoken = ""; if (httpcontext.current.request.cookies["securitytoken"] != null) { securitytoken = httpcontext.current.request.cookies["securitytoken"].value.tostring(); } var user = user.getloggedinuser(securitytoken); if (user != null) { var convertedcampaignid = request.querystring["cid"]; //if querystring exists process else force if (!string.isnullorwhitespace(convertedcampaignid)) { using (var campaignrepository = new campaignrepository()) { var campaign = campaignrepository.getcampaignbyid(convertedcampaignid, user.userid); //does campaign exist passed in query string, if (campaign != null) { ccid = "'" + campaign.convertedcampaignid + "'"; //build navigation stringbuilder sbnav = new stringbuilder(); string nav = kto.common.reader.readfile("/templates/html/side-nav.html"); sbnav.appendline(nav.replace("{convertedcampaignid}", campaign.convertedcampaignid)); ltlnavitems.text = sbnav.tostring(); ltlcampaignname.text = "campaign: " + "<strong>" + campaign.name + "</strong>"; //get campaigns dropdown ienumerable<campaign> campaigns = campaignrepository.getcampaigns(user.userid); stringbuilder sbcampaigns = new stringbuilder(); string strcampaigns = "<li title='{campaignname}' data-cid='{convertedcampaignid}' class='js-campaign-item'>" + "<p class='name-message'><a href='/panel/c/{convertedcampaignid}/' class='campaign-lnk'>{campaignname}</a>" + "</p>" + "</li>"; foreach (var c in campaigns) { sbcampaigns.appendline(strcampaigns.replace("{convertedcampaignid}", c.convertedcampaignid) .replace("{campaignid}", c.campaignid.tostring()) .replace("{campaignname}", c.name)); } } else { response.redirect("/notifications/404/"); } } } else { response.redirect("/notifications/404/"); } } else { response.redirect("/login/"); } }
derived page logic:
protected void btninviteusers_click(object sender, eventargs e) { if (txtemail.text.trim() != "") { if (txtemail.text.trim().length < 75) { if (common.email.isvalidemail(txtemail.text.trim()) == true) { string securitytoken = ""; if (httpcontext.current.request.cookies["securitytoken"] != null) { securitytoken = httpcontext.current.request.cookies["securitytoken"].value.tostring(); } var user = business.entity.user.getloggedinuser(securitytoken); if (user != null) { try { using (var userrepo = new userrepository()) { var userinsystem = userrepo.userexists(txtemail.text.trim().removehtml()); if (userinsystem == true) { ltlreturnmessage.text = "unfortunately cannot send request, user exists."; } else { //craft querystring string encryptedemail = user.encryptedemail; int uid = user.userid; string userinvitehtml = common.reader.readfile("/templates/emails/user-invite.html"); stringbuilder sb = new stringbuilder(); sb.appendline(userinvitehtml.replace("{link}", "http://localhost:52447/_user-invite/?inor-t-em=" + encryptedemail + "&inor-d=" + uid.tostring())); common.email.sendmail(txtemail.text.trim(), "", "", user.firstname + " " + user.lastname + " invited join x", sb.tostring()); ltlreturnmessage.text = "invite sent!"; } } } catch { ltlreturnmessage.text = "problem sending invite, please try again."; } } } else { ltlreturnmessage.text = "are sure that's email address? please try again."; } } else { ltlreturnmessage.text = "email address must not exceed 75 characters."; } } else { ltlreturnmessage.text = "email address required."; } }
please consider method return "campaign" on page not when page posts back.
after scrutinising every last line, noticed query string duplicated. when button click event fired derived page post running logic on master page. assume played havoc url-rewriting.
i fixed adding
frminviteuser.action = request.rawurl;
within page_load of derived page, force request of url , not postback master.
this why getting null on method, param passed duplicated.
regards,
Comments
Post a Comment